By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,677 Members | 1,877 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,677 IT Pros & Developers. It's quick & easy.

slow performance on specific query

P: n/a
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
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Not Me (no*****@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, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2

P: n/a
Erland Sommarskog wrote:
Not Me (no*****@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
Jul 23 '05 #3

P: n/a
Not Me (no*****@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, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.