July 17, 2009 at 7:59 am
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.
July 17, 2009 at 8:51 am
Are all your statistics upto date ?
The actual row counts differ vastly from the estimates.
July 17, 2009 at 10:02 am
Yes I have updated the stats.
July 17, 2009 at 10:12 am
You may want to check out this blog post[/url] by Grant Fritchey as it applies to your query.
What happens if you remove the TOP operator.
Jack Corbett
Consultant - Straight Path Solutions
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
July 17, 2009 at 11:51 am
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
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
July 17, 2009 at 12:43 pm
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.
July 17, 2009 at 12:52 pm
Try running with a recompile hint. You might be just re-using the cached plan.
Jack Corbett
Consultant - Straight Path Solutions
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
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply