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 12»»

Unexpected View Performance Expand / Collapse
Author
Message
Posted Monday, January 10, 2011 8:11 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, June 14, 2013 9:41 AM
Points: 88, Visits: 262
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]
Post #1045669
Posted Tuesday, January 11, 2011 12:32 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum 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)
Post #1045716
Posted Tuesday, January 11, 2011 4:40 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC 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

Post #1045802
Posted Tuesday, January 11, 2011 5:47 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, June 15, 2013 5:11 PM
Points: 40, Visits: 235
"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';

Post #1045830
Posted Tuesday, January 11, 2011 7:14 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: 2 days ago @ 3:37 AM
Points: 4, Visits: 108
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
Post #1045889
Posted Tuesday, January 11, 2011 7:52 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 3:22 PM
Points: 3,678, Visits: 5,177
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
Post #1045909
Posted Tuesday, January 11, 2011 8:02 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, June 14, 2013 10:11 AM
Points: 56, Visits: 492
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
Post #1045916
Posted Tuesday, January 11, 2011 8:30 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, June 14, 2013 9:41 AM
Points: 88, Visits: 262
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]
Post #1045936
Posted Tuesday, January 11, 2011 12:06 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Wednesday, May 22, 2013 7:11 AM
Points: 877, Visits: 1,159
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
Post #1046073
Posted Wednesday, January 12, 2011 5:43 AM
SSC-Enthusiastic

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

Group: General Forum Members
Last Login: Saturday, June 15, 2013 2:09 AM
Points: 155, Visits: 1,301
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

Post #1046418
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse