June 28, 2006 at 12:34 pm
This query takes quite a while to run and I'm wondering if there is anything I could do to speed it up?
SELECT ReplyREI.dbo.Reply_PropertyInformation.PropertyAddressState AS STATE, neighborhoodinfo.dbo.Profiles.POPCY, neighborhoodinfo.dbo.Profiles.POPDIF90CY, neighborhoodinfo.dbo.Profiles.ZIP,
neighborhoodinfo.dbo.Profiles.ZIPNAME AS CITY
FROM ReplyREI.dbo.Reply_PropertyInformation RIGHT OUTER JOIN
neighborhoodinfo.dbo.Profiles ON neighborhoodinfo.dbo.Profiles.ZIP = ReplyREI.dbo.Reply_PropertyInformation.PropertyAddressZip
WHERE neighborhoodinfo.dbo.Profiles.ZIP IS NOT NULL
June 28, 2006 at 12:37 pm
how many results is it returning?
June 28, 2006 at 12:51 pm
I returns millions of rows. I have another proc that narrows down the server further, but I wasn't sure about the join..
June 28, 2006 at 12:56 pm
Add this before your query and post the results of the ShowPlan:
Set Showplan_Text On
go
Set NoExec on
go
Also, you can make your query more concise and easier to read if you adopt table aliases instead of replicating the 3-part naming of each object:
SELECT pi.PropertyAddressState AS STATE,
p.POPCY,
p.POPDIF90CY,
p.ZIP,
p.ZIPNAME AS CITY
FROM ReplyREI.dbo.Reply_PropertyInformation As pi
RIGHT OUTER JOIN neighborhoodinfo.dbo.Profiles As p
ON p.ZIP = pi.PropertyAddressZip
WHERE p.ZIP IS NOT NULL
June 28, 2006 at 12:59 pm
Thanks in advance for your help.
StmtText
----------------
Set NoExec on
(1 row(s) affected)
StmtText
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SELECT pi.PropertyAddressState AS STATE,
p.POPCY,
p.POPDIF90CY,
p.ZIP,
p.ZIPNAME AS CITY
FROM ReplyREI.dbo.Reply_PropertyInformation As pi
RIGHT OUTER JOIN neighborhoodinfo.dbo.Profiles As p
ON p.ZIP = pi.PropertyAddressZip
WHERE p.ZIP IS NOT NULL
(1 row(s) affected)
StmtText
-------------------------------------------------------------------------------------------------------------------------------
|--Hash Match(Left Outer Join, HASH[p].[ZIP])=([pi].[PropertyAddressZip]), RESIDUAL[p].[ZIP]=[pi].[PropertyAddressZip]))
|--Clustered Index Scan(OBJECT[NeighborhoodInfo].[dbo].[Profiles].[PK_Profiles] AS [p]), WHERE[p].[ZIP]<>NULL))
|--Index Scan(OBJECT[ReplyREI].[dbo].[Reply_PropertyInformation].[idx_AdvancedSearch] AS [pi]))
(3 row(s) affected)
June 28, 2006 at 3:09 pm
You may be able to get a bit more performance out of it by changing this...
WHERE neighborhoodinfo.dbo.Profiles.ZIP IS NOT NULL
...to this...
WHERE neighborhoodinfo.dbo.Profiles.ZIP > '00000'
... which will also exclude "bad" zip codes and "blank" zip codes.
Also, I'd check to see if all of the tables in your SELECT are tables...
I've troubleshot many a slow running query only to find out that it wasn't the query,
it was referencing one (or more) poorly written views. See if some of the tables
are views and see what THEIR execution plans look like.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 28, 2006 at 3:20 pm
THanks for the help...
Susan
June 29, 2006 at 1:49 am
Index columns with ZIP codes in both tables.
And don't return million rows.
Change this SP to a view. And select in following SP from this view.
It will allow optimiser to narrow hash tables and ease the load on server.
_____________
Code for TallyGenerator
June 29, 2006 at 4:54 am
I think someone needs to look at the data in the tables. How many times is a ZipCode listed in the neigborhood Profiles table? You could be spawning dozens or even hundreds of unwanted (duplicate) records for each property zipcode. Yes, DISTINCT may help but that may be treating the symptom, not the problem.
I think before we simply transfer the problem to, what could turn out to be, a farily bloated denormalized view, I think someone needs to look at the data, figure out why millions of rows are being returned, and correctly define the problem.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply