Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Query performance for Ordering Expand / Collapse
Author
Message
Posted Friday, July 17, 2009 7:59 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, July 16, 2014 12:10 PM
Points: 176, Visits: 292
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 (17 views, 66.56 KB)
Post #754846
Posted Friday, July 17, 2009 8:51 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 5:33 AM
Points: 1,949, Visits: 8,313
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
Posted Friday, July 17, 2009 10:02 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, July 16, 2014 12:10 PM
Points: 176, Visits: 292
Yes I have updated the stats.


Post #754963
Posted Friday, July 17, 2009 10:12 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 10:50 AM
Points: 11,264, Visits: 13,022
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
Posted Friday, July 17, 2009 11:51 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 10:09 AM
Points: 15,661, Visits: 28,050
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
Posted Friday, July 17, 2009 12:43 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, July 16, 2014 12:10 PM
Points: 176, Visits: 292
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
Posted Friday, July 17, 2009 12:52 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 10:50 AM
Points: 11,264, Visits: 13,022
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 »

Add to briefcase

Permissions Expand / Collapse