SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Query performance for Ordering


Query performance for Ordering

Author
Message
reddyk
reddyk
SSC-Enthusiastic
SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)

Group: General Forum Members
Points: 192 Visits: 303
The table schema and indexes and exec plan is attached. I have added indexes but have not seen any improvement. My production server is a 64 bit, 8 processor 2.66GHz 16GB of RAM running 2005 SP2.

SELECT top (10000)
PC.tpcGCProviderID AS nbaGCProviderID,
PC.tpcLocationID AS nbaLocationID,
P.tpProviderType nbaProviderType,
P.tpLastName as nbaLastName,
P.tpFirstName as nbaFirstName,
P.tpCredentials as nbaCredentials,
P.tpGroupName as nbaGroupName,
PL.tplAddrLine1 nbaAddress,
PL.tplCity as nbaCity,
PL.tplState as nbaState, PL.tplCounty,
LEFT(PL.tplZipCode, 5) AS nbaZip,
PC.tpcPhone as nbaBusinessPhone,
PC.tpcFaxPhone as nbaFaxPhone, PC.tpcNetwork as nbaNetwork,
NetworkPreference.PreferenceOrder
FROM dbo.tbl_ProviderCoverage pc
inner join dbo.tbl_Provider as p on p.tpGCProviderID=pc.tpcGCProviderID
inner join dbo.tbl_ProviderLocation pl on pl.tplLocationID=pc.tpcLocationID
INNER JOIN dbo.NetworkPreference
ON NetworkName = pc.tpcNetwork
WHERE pl.tplAddressType = 'L'
AND pl.tplState = 'ga'
and PL.tplZipLatitude BETWEEN 33.386676 and 34.111314
AND PL.tplZipLongitude BETWEEN -84.750301 and -84.025663
and p.tpprovidertype='physician'
AND (PC.tpcEffDate < DATEADD(year, 1, GETDATE()))
AND (PC.tpcTermDate > DATEADD(year, 1, GETDATE()))
AND CustomerNum = 'DEfault'
ORDER BY NetworkPreference.PreferenceOrder
GO


--Schema
CREATE TABLE [dbo].[tbl_Provider](
[tpGCProviderID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[tpProviderType] [char](9) NOT NULL,
[tpLastName] [varchar](50) NULL,
[tpFirstName] [varchar](50) NULL,
[tpMiddleInit] [char](1) NULL,
[tpSuffix] [char](10) NULL,
[tpCredentials] [char](10) NULL,
[tpGroupName] [varchar](100) NULL,
CONSTRAINT [PK_tbl_Provider_1] PRIMARY KEY CLUSTERED
(
[tpGCProviderID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [primary]
) ON [PRIMARY]

GO
CREATE TABLE [dbo].[tbl_ProviderCoverage](
[tpcID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[tpcGCProviderID] [numeric](18, 0) NOT NULL,
[tpcLocationID] [numeric](18, 0) NOT NULL,
[tpcTaxID] [varchar](50) NOT NULL,
[tpcNetwork] [varchar](50) NOT NULL,
[tpcEffDate] [datetime] NOT NULL,
[tpcTermDate] [datetime] NULL,
[tpcNationalPID] [varchar](50) NULL,
[tpcProviderID] [varchar](50) NULL,
[tpcDateCreated] [datetime] NULL,
[tpcDateUpdated] [datetime] NULL,
[tpcUserName] [varchar](50) NULL,
[tpcPhone] [char](10) NULL,
[tpcFaxPhone] [char](10) NULL,
CONSTRAINT [PK_tbl_ProviderCoverage] PRIMARY KEY CLUSTERED
(
[tpcID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

CREATE TABLE [dbo].[tbl_ProviderLocation](
[tplLocationID] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[tplAddressType] [char](1) NULL,
[tplAddrLine1] [varchar](50) NULL,
[tplAddrLine2] [varchar](50) NULL,
[tplCity] [varchar](50) NULL,
[tplState] [char](2) NULL,
[tplZipCode] [char](9) NULL,
[tplCounty] [varchar](50) NULL,
[tplCountry] [varchar](50) NULL,
[tplLatitude] [decimal](10, 6) NULL,
[tplLongitude] [decimal](10, 6) NULL,
[tplDateCreated] [datetime] NULL,
[tplDateUpdated] [datetime] NULL,
[tplUserName] [varchar](50) NULL,
[tplFIPS_StateCode] [char](2) NULL,
[tplFIPS_CountyCode] [char](3) NULL,
[tplGeoCodeError] [bit] NOT NULL CONSTRAINT [DF_tbl_ProviderLocation_tplGeoCodeError] DEFAULT (0),
[tplZipLatitude] [decimal](10, 6) NULL,
[tplZipLongitude] [decimal](10, 6) NULL,
CONSTRAINT [PK_tbl_ProviderLocation] PRIMARY KEY CLUSTERED
(
[tplLocationID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [primary]
) ON [pRIMARY]

GO
CREATE TABLE [dbo].[NetworkPreference](
[CustomerNum] [nvarchar](10) NULL,
[State] [nvarchar](2) NULL,
[PreferenceOrder] [int] NULL,
[NetworkSubName] [nvarchar](8) NULL,
[NetworkName] [nvarchar](20) NULL,
[PmPmPricing] [money] NULL,
[PerCentPricing] [int] NULL,
[CheckSubTable] [nvarchar](1) NULL,
[nprReferralSavingsPercent] [numeric](18, 3) NULL,
[nprID] [int] IDENTITY(1,1) NOT NULL
) ON [PRIMARY]

GO

/****** Object: Index [IX_CustomerNum] Script Date: 07/17/2009 09:51:37 ******/
CREATE CLUSTERED INDEX [IX_CustomerNum] ON [dbo].[NetworkPreference]
(
[CustomerNum] ASC,
[PreferenceOrder] ASC,
[NetworkName] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO


/****** Object: Index [IX_AddTypeStLongLatLocIDAddrCityCountyCoverinfZip] Script Date: 04/28/2009 12:48:35 ******/
CREATE NONCLUSTERED INDEX [IX_AddTypeStLongLatLocIDAddrCityCountyCoverinfZip] ON [dbo].[tbl_ProviderLocation]
(
[tplAddressType] ASC,
[tplState] ASC,
[tplZipLongitude] ASC,
[tplZipLatitude] ASC,
[tplLocationID] ASC,
[tplAddrLine1] ASC,
[tplCity] ASC,
[tplCounty] ASC
)
INCLUDE ( [tplZipCode]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
CREATE NONCLUSTERED INDEX [IX_LocIDNetworkCoveringEffDateTermDate] ON [dbo].[tbl_ProviderCoverage]
(
[tpcLocationID] ASC,
[tpcNetwork] ASC,
[tpcID] ASC,
[tpcGCProviderID] ASC,
[tpcPhone] ASC
)
INCLUDE ( [tpcEffDate],
[tpcTermDate],
[tpcFaxPhone]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF,
IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON,
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
go

CREATE NONCLUSTERED INDEX [IX_ProvIdTypeLNameFNameCredGName] ON [dbo].[tbl_Provider]
(
[tpGCProviderID] ASC,
[tpProviderType] ASC,
[tpLastName] ASC,
[tpFirstName] ASC,
[tpCredentials] ASC,
[tpGroupName] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

CREATE NONCLUSTERED INDEX [IX_ProviderIdTypeCoveringLNameFNameCredGName] ON [dbo].[tbl_Provider]
(
[tpGCProviderID] ASC,
[tpProviderType] ASC
)
INCLUDE ( [tpLastName],
[tpFirstName],
[tpCredentials],
[tpGroupName]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]


--All the indexex above are used by the query in the execution plan....

Any help is greatly appreciated.



Attachments
EXECPLAN.sqlplan (27 views, 66.00 KB)
Dave Ballantyne
Dave Ballantyne
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12814 Visits: 8370
Are all your statistics upto date ?
The actual row counts differ vastly from the estimates.



Clear Sky SQL
My Blog
reddyk
reddyk
SSC-Enthusiastic
SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)

Group: General Forum Members
Points: 192 Visits: 303
Yes I have updated the stats.



Jack Corbett
  Jack Corbett
SSC Guru
SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)

Group: General Forum Members
Points: 79460 Visits: 14974
You may want to check out this blog post by Grant Fritchey as it applies to your query.

What happens if you remove the TOP operator.



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (164K reputation)SSC Guru (164K reputation)SSC Guru (164K reputation)SSC Guru (164K reputation)SSC Guru (164K reputation)SSC Guru (164K reputation)SSC Guru (164K reputation)SSC Guru (164K reputation)

Group: General Forum Members
Points: 164396 Visits: 33202
Did you try updating the statisitics with a FULL SCAN? They're pretty widely out of line. That's frequently an indication that they're out of date.

You're getting a loop join on 10000 records. That should be a hash, I'm sure.

I'd try updating the statistics again, using the full scan. The optimizer is making some pretty poor choices here.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
reddyk
reddyk
SSC-Enthusiastic
SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)SSC-Enthusiastic (192 reputation)

Group: General Forum Members
Points: 192 Visits: 303
I get data in seconds without the top operator. I will check out the blog. Its really frustating as i have tried rewriting it different ways, I updated stats with full scan changed the clustered index on the coverage table. I cant seem to get rid of the nested loops. Any help is appreciated.



Jack Corbett
  Jack Corbett
SSC Guru
SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)SSC Guru (79K reputation)

Group: General Forum Members
Points: 79460 Visits: 14974
Try running with a recompile hint. You might be just re-using the cached plan.



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search