Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Optimization

Author  Topic 

dim
Yak Posting Veteran

57 Posts

Posted - 2011-01-24 : 17:58:13
Hi,

I have a datbase table which stores data at a detail level ( each day has more than 100 rows ). The table captures data for the time period 2 years worth data with 3018918 rows. I have a view which pulls data from this table.

At present it does take some time to retrieve data. Is there a possible way to improve the performance so that the data retireval is faster?


Thank you,
dim

Dp

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-01-24 : 18:12:16
Yes, you'll need to see what indexes you are missing. Can you post your query/view/DDL for the table(s) including indexes?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dim
Yak Posting Veteran

57 Posts

Posted - 2011-01-24 : 18:24:57
Hi,

I guess I have just one index on the table defined. [PK_Service_Metric] PRIMARY KEY CLUSTERED

USE [AFRTY]
GO
/****** Object: Table [dbo].[Services_Metrics] Script Date: 01/24/2011 18:16:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Services_Metrics](
[metric_key] [int] IDENTITY(1,1) NOT NULL,
[date_key] [int] NOT NULL,
[Center_Key] [int] NOT NULL,
[Driver_Key] [int] NOT NULL,
[P_Type_Key] [char](2) NOT NULL,
[S_Type_Key] [varchar](2) NOT NULL,
[F_Key] [int] NOT NULL,
[Res_Key] [int] NOT NULL,
[Status_Reason_Key] [int] NOT NULL,
[Agent_Key] [int] NULL,
[Call_Key] [int] NULL,
[transaction_audit_key] [int] NOT NULL,
[Battery_Calls] [int] NULL CONSTRAINT [DF_Battery_Cell] DEFAULT ((0)),
[Battery_Sales] [int] NULL CONSTRAINT [DF_Battery_Sales] DEFAULT ((0)),
[Warranty_Battery_Sales] [int] NULL CONSTRAINT [DF_Warranty_Battery_Sales] DEFAULT ((0)),
[RE_OL] [int] NULL CONSTRAINT [DF_RE_OL] DEFAULT ((0)),
[RE_OL_Average_Of_Total] [int] NULL CONSTRAINT [DF_RE_OL_AVG_OF_Total] DEFAULT ((0)),
[Under_30_Minutes] [int] NULL CONSTRAINT [DF_Under_30_Mins] DEFAULT ((0)),
[Number_of_OTA_Calls] [int] NULL DEFAULT ((0)),
[Number_of_6LD_Calls] [int] NULL DEFAULT ((0)),
[Number_of_GOA_Calls] [int] NULL DEFAULT ((0)),
[Number_of_Paid_Calls] [int] NULL CONSTRAINT [DF_Number_Of_Paid_Calls] DEFAULT ((0)),
[Number_of_Total_Calls] [int] NULL DEFAULT ((0)),
[RA_Paid_Call_Volume] [int] NULL CONSTRAINT [DF_RA_Paid_Call_Volume] DEFAULT ((0)),
[Roadside_Assistance_Responce_Time] [int] NULL CONSTRAINT [DF_Roadside_Assitance_Resonce_Time] DEFAULT ((0)),
[RA_Quaility_Scores] [int] NULL CONSTRAINT [DF_RA_Quaility_Scores] DEFAULT ((0)),
[COR_Car_Counts] [int] NULL CONSTRAINT [DF_COR_Car_Cnts] DEFAULT ((0)),
[Battery_Installations] [int] NULL CONSTRAINT [DF_Batter_Installations] DEFAULT ((0)),
[Number_of_Glass_Jobs] [int] NULL CONSTRAINT [DF_Number_Of_Glass_Jobs] DEFAULT ((0)),
[Extended_Warranty_Sales] [int] NULL CONSTRAINT [DF_Extended_Warranty_Sales] DEFAULT ((0)),
[New_Car_Sales] [int] NULL CONSTRAINT [DF_New_Car_Sales] DEFAULT ((0)),
[Used_Car_Sales] [int] NULL CONSTRAINT [DF_Used_Car_Sales] DEFAULT ((0)),
[CC_Activations] [int] NULL CONSTRAINT [DF_CC_Activations] DEFAULT ((0)),
[Number_of_calls_without_cancel] [int] NULL DEFAULT ((0)),
[TLC Code Desc] [varchar](20) NULL,
[Received time] [datetime] NULL,
[On Location time] [datetime] NULL,
[Call Cleared time] [datetime] NULL,
CONSTRAINT [PK_Service_Metric] PRIMARY KEY CLUSTERED
(
[metric_key] ASC,
[transaction_audit_key] ASC,
[Driver_Key] ASC,
[Center_Key] ASC,
[date_key] ASC,
[P_Type_Key] ASC,
[S_Type_Key] ASC,
[F_Key] ASC,
[Res_Key] ASC,
[Status_Reason_Key] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

Let me know




Dp
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-01-24 : 18:29:41
You'll need to show us the query as well as the view.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dim
Yak Posting Veteran

57 Posts

Posted - 2011-01-24 : 18:33:17
Hi,

The view is nothing but a select of the above table. No computations at all. I was concerned whether we can reduce the time by applying appropriate index at the table level to reduce the time.


Dp
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-01-24 : 18:37:12
We'll need to see your query then. We can't just guess what query you are running. Adding the indexes depends entirely on your query (at this point at least).

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dim
Yak Posting Veteran

57 Posts

Posted - 2011-01-24 : 18:44:12

Hi,

This is the query:
SELECT
dbo.vw2_Dim_Date.Date,
dbo.vw2_Dim_Facilities.Facility_Code,
dbo.vw2_Dim_Facilities.Facility_Name,
dbo.vw2_Dim_Facilities.Facility_Code + ' ' + dbo.vw2_Dim_Facilities.Facility_Name,
dbo.vw2_Dim_Fleet_Driver.Fleet_Driver_Last_Name + ' ' + dbo.vw2_Dim_Fleet_Driver.Fleet_Driver_First_Name + ' , ' + dbo.vw2_Dim_Fleet_Driver.Fleet_Driver_Code,
dbo.vw2_Dim_Fleet_Driver.Fleet_Driver_Code,
dbo.vw2_Dim_Call_Types.Call_Type_Code,
dbo.vw2_Dim_Call_Types.Call_Type_Description,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver."TLC Code Desc",
dbo.vw2_Dim_Resolutions.Resolution_Code,
dbo.vw2_Dim_Resolutions.Resolution_Description,
dbo.vw2_Dim_Cost_Centers.Cost_Center_Code,
dbo.vw2_Dim_Cost_Centers.Cost_Center_Description,
dbo.vw2_Dim_Cost_Centers.Cost_Center_Location,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Recd_Time,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Call_Clear_Time,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.On_Loc_Time,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Difference_OL_Cleared_Time,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Difference_Received_Time_Cleared_Time,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Received_Time_Minutes,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.On_Location_Time_Minutes,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Call_Cleared_Time_Minutes,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Difference_Received_Time_Cleared_Time_Minutes,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Difference_On_Location_Time_Cleared_Time_Minutes,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.RE_OL_Average_Of_Total,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Number_of_Total_Calls,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Under_30_Minutes,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Number_of_OTG_Calls,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Number_of_6L_Calls,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Number_of_GOA_Calls,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Battery_Calls,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Battery_Sales,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Warranty_Battery_Sales,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Number_of_calls_without_cancel
FROM
dbo.vw2_Dim_Date,
dbo.vw2_Dim_Facilities,
dbo.vw2_Dim_Fleet_Driver,
dbo.vw2_Dim_Call_Types,
dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver,
dbo.vw2_Dim_Resolutions,
dbo.vw2_Dim_Cost_Centers
WHERE
( dbo.vw2_Dim_Date.date_key=dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.date_key )
AND ( dbo.vw2_Dim_Fleet_Driver.Fleet_Driver_Key=dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Fleet_Driver_Key )
AND ( dbo.vw2_Dim_Facilities.Facility_Key=dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Facility_Key )
AND ( dbo.vw2_Dim_Resolutions.Resolution_Key=dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Resolution_Key )
AND ( dbo.vw2_Dim_Call_Types.Call_Type_Key=dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Call_Type_Key )
AND ( dbo.vw2_Dim_Cost_Centers.Cost_Center_Key=dbo.vw2_Fact_Automotive_Service_Call_Details_By_Driver.Cost_Center_Key )
AND
(
dbo.vw2_Dim_Fleet_Driver.Fleet_Driver_Code <> '?'
AND
dbo.vw2_Dim_Date.Date >= '01/01/2009'
AND
dbo.vw2_Dim_Date.Date <= '01/01/2010'
)




Dp
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-01-24 : 19:06:03
Are the join conditions indexed? You should start there.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

dim
Yak Posting Veteran

57 Posts

Posted - 2011-01-25 : 20:25:04
Hi tkizer....yes I indexed the join condition and it kind of improved the result retrieval. Also would it help to do the same for the underlying view?



Dp
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-01-26 : 01:01:01
It's really hard for us to help unless we have the complete picture. Script out the view, all tables and indexes associated with the view, and post it here.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -