Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
SQL Server 2005 Performance Tuning
»
Query performance for Ordering
Query performance for Ordering
Rate Topic
Display Mode
Topic Options
Author
Message
reddyk
reddyk
Posted Friday, July 17, 2009 7:59 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Monday, May 20, 2013 8:45 AM
Points: 174,
Visits: 268
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.
Post Attachments
EXECPLAN.sqlplan
(
16 views,
66.56 KB
)
Post #754846
Dave Ballantyne
Dave Ballantyne
Posted Friday, July 17, 2009 8:51 AM
SSCommitted
Group: General Forum Members
Last Login: Today @ 3:42 AM
Points: 1,943,
Visits: 8,228
Are all your statistics upto date ?
The actual row counts differ vastly from the estimates.
Clear Sky SQL
My Blog
Kent user group
Post #754890
reddyk
reddyk
Posted Friday, July 17, 2009 10:02 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Monday, May 20, 2013 8:45 AM
Points: 174,
Visits: 268
Yes I have updated the stats.
Post #754963
Jack Corbett
Jack Corbett
Posted Friday, July 17, 2009 10:12 AM
SSChampion
Group: General Forum Members
Last Login: Friday, May 17, 2013 12:22 PM
Points: 10,571,
Visits: 11,871
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
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
Post #754973
Grant Fritchey
Grant Fritchey
Posted Friday, July 17, 2009 11:51 AM
SSChampion
Group: General Forum Members
Last Login: Today @ 3:41 AM
Points: 13,383,
Visits: 25,189
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 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans
Product Evangelist for
Red Gate Software
Post #755047
reddyk
reddyk
Posted Friday, July 17, 2009 12:43 PM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Monday, May 20, 2013 8:45 AM
Points: 174,
Visits: 268
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.
Post #755072
Jack Corbett
Jack Corbett
Posted Friday, July 17, 2009 12:52 PM
SSChampion
Group: General Forum Members
Last Login: Friday, May 17, 2013 12:22 PM
Points: 10,571,
Visits: 11,871
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
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
Post #755080
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.