Unix Technical Forum

slow performance on specific query

This is a discussion on slow performance on specific query within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi, Can't post specifics at the moment but if this seems like a common problem any help would be ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 07:30 AM
Not Me
 
Posts: n/a
Default slow performance on specific query

Hi,

Can't post specifics at the moment but if this seems like a common
problem any help would be appreciated.

When querying with ~6 tables, using mostly left outer joins, I get
standard performance with the where clause

where XXX is not null

however, if I try the clause

where XXX = 4

the query takes upwards of 5-6 minutes (I just stop it running at that
point.

The field XXX is in the 'main' table (to which the joins attach), it's
an integer field too so I can't see too many problems there.

There's no index on the XXX field, but if I remove the joins, I get
standard performance doing either query.

So why would the second query's performance differ so significantly?

Cheers,
Chris
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 07:30 AM
Erland Sommarskog
 
Posts: n/a
Default Re: slow performance on specific query

Not Me (notme.n@da.com.hk.org) writes:
> Can't post specifics at the moment but if this seems like a common
> problem any help would be appreciated.
>...
> So why would the second query's performance differ so significantly?


Well, if you can post the specifics, the answer you get will neither
be very specific.

All I can say is that SQL Server uses a cost-based optimizer that makes
it descisions from statistics collected about the data in the table. From
these statistics it makes estimates about which plan is the best. Statistics
can be out of date, and even if they are not, the statistics are samples
that can be skewed. And, in the course of computing plans for a six-way
join a small error in an initial estimate can give a huge error in the end.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 07:31 AM
Not Me
 
Posts: n/a
Default Re: slow performance on specific query

Erland Sommarskog wrote:
> Not Me (notme.n@da.com.hk.org) writes:
>
>>Can't post specifics at the moment but if this seems like a common
>>problem any help would be appreciated.
>>...
>>So why would the second query's performance differ so significantly?

>
>
> Well, if you can post the specifics, the answer you get will neither
> be very specific.


Yup, I understand that.

Well I first tried putting the where clause into a subquery where that
table joined the others, this didn't affect the results. Then I tried
performing that query seperately, creating a temporary table, then using
that in the join for the second query. This gave me what I wanted, a
result in seconds rather than minutes.

Cheers,
Chris
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 07:31 AM
Erland Sommarskog
 
Posts: n/a
Default Re: slow performance on specific query

Not Me (notme.n@da.com.hk.org) writes:
> Well I first tried putting the where clause into a subquery where that
> table joined the others, this didn't affect the results. Then I tried
> performing that query seperately, creating a temporary table, then using
> that in the join for the second query. This gave me what I wanted, a
> result in seconds rather than minutes.


Yes, sometimes that can be a useful strategy to impose a join order that
the optimizer does not find itself. When you do this you should be fairly
confident that this is the right order today, but also tomorrow.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:00 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com