|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Today @ 3:11 PM
Points: 88,
Visits: 258
|
|
Comments posted to this topic are about the item Unexpected View Performance
Thom Bolin - MCITP SQLServer 2005 NTXDBA Blog[url=http://ntxdba.blogspot.com/][/url]
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Sunday, June 17, 2012 2:20 AM
Points: 4,
Visits: 30
|
|
Hello,
Thanks for writing this article, in my search for a solution of a performance problem I ran into your post and it has helped me partly so far. I do have a question though:
You're saying "This same statement executed outside of the view uses an Index Seek on both tables.", can you show what statement that is? If I try:
SELECT accountnumber FROM ( SELECT accountnumber FROM agents2009 UNION ALL SELECT accountnumber FROM agents ) vwInline WHERE accountnumber = 'QOT039365'
I don't see any difference in the queryplan from replacing the subquery with the view.
regards, Sebastiaan
The normal form of a database is inversely proportional to that of the designer (This message was generated with 100% recycled electrons)
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Sunday, October 28, 2012 4:19 AM
Points: 94,
Visits: 290
|
|
Hi,
Can you draw the conclusion in other words ?
Regards Kumar Harsh
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: 2 days ago @ 4:28 PM
Points: 39,
Visits: 229
|
|
"This same statement executed outside of the view uses an Index Seek on both tables."
Like you, I get the same plan as the view with a select from a derived table. However, seeks do occur against both tables if separate WHERE clauses are specified with each SELECT of the UNION ALL. So I am guessing that it wasn't really the same statement that Thom ran from SSMS:
SELECT accountnumber FROM agents2009 WHERE accountnumber = 'QOT039365' UNION ALL SELECT accountnumber FROM agents WHERE accountnumber = 'QOT039365';
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 8:59 AM
Points: 4,
Visits: 98
|
|
Hi All
The main reason for degradation in performance here is that the query filter was not supplied in the exact format that index was created in.
To be honest this doesnt really have all that much to do with the fact that you are querying data from a view.
If you want sql to use an index in its query plan the filter must be supplied in exactly the same format as the column indexed on the table
if the index is built on a column of type smallint and you sent in an int as a filter the plan will use a full table scan instead of an index seek
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Today @ 2:32 PM
Points: 3,575,
Visits: 5,115
|
|
There are sooooo many ways using inconsistent datatypes can harm performance! I have been preaching this to clients (and cleaning up messes related to it) for over a decade now!!
Best,
Kevin G. Boles SQL Server Consultant SQL MVP 2007-2012 TheSQLGuru at GMail
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 9:15 AM
Points: 56,
Visits: 487
|
|
Thanks for posting this. I found it very insightful and relieving because I thought I was the only person that missed things like this. It took you a long time to figure this one out (it would have taken me longer) and it's so close to the surface I bet you even gave it a thought in the beginning. I can almost see the process...
"Hmmm...it's gotta be an index. Perhaps this Varchar(9) and Varchar(10) thing would be an issue....NAH, you can't get any closer to matching datatypes than that!"
At least, that's how my brain would have seen it. Then, it would have been the absolute LAST thing I tried, because, "there's NO WAY a varchar(9) and varchar(10) would make a difference".
Again, thanks for posting and making your findings clear and concise (nice code and screenshots).
Gabe
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Today @ 3:11 PM
Points: 88,
Visits: 258
|
|
The statement executed outside of the view is the one below, filter added to both of the select statements.
SELECT accountnumber FROM agents2009 WHERE accountnumber = ''QOT039365' UNION ALL SELECT accountnumber FROM agents WHERE accountnumber = ''QOT039365'
Hope this help clears up the question.
Thom Bolin - MCITP SQLServer 2005 NTXDBA Blog[url=http://ntxdba.blogspot.com/][/url]
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 2:42 PM
Points: 877,
Visits: 1,158
|
|
Nice article. This is a good example of just a single typo or miss in declaring the column data type/length can harm your performance and you need to spend a week to resolve the issue.
Thanks
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 8:30 AM
Points: 153,
Visits: 1,278
|
|
Thanks for sharing your observation. Now we know that 'near-enough' may be a long way from 'identical' when it comes to datatypes
Cheers,
JohnA
|
|
|
|