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

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: Wednesday, August 6, 2014 12:50 PM
Points: 88, Visits: 286
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, August 3, 2014 10:22 PM
Points: 97, Visits: 324
Hi,

Can you draw the conclusion in other words ?


Regards
Kumar Harsh

Post #1045802
Posted Tuesday, January 11, 2011 5:47 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, August 25, 2014 3:38 PM
Points: 55, Visits: 294
"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: Thursday, January 30, 2014 3:08 AM
Points: 4, Visits: 117
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


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: 2 days ago @ 4:33 PM
Points: 4,358, Visits: 6,193
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
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, September 18, 2014 9:18 AM
Points: 80, Visits: 729
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: Wednesday, August 6, 2014 12:50 PM
Points: 88, Visits: 286
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


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Sunday, September 7, 2014 10:22 PM
Points: 1,126, Visits: 1,387
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: Thursday, April 17, 2014 1:41 AM
Points: 170, Visits: 1,400
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

MCM: SQL2008
Post #1046418
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse