You are here: Re: Why is a simple WHERE clause so slow? « MsSQL Server « IT news, forums, messages
Re: Why is a simple WHERE clause so slow?

Posted by Gert-Jan Strik on 01/12/07 18:56

Emin wrote:
>
> Dear Experts,
>
> I have a fairly simple query in which adding a where clause slows
> things down by at least a factor of 100. The following is the slow
> version of the query
>
> -------------------------
> SELECT * FROM
> ( Select x.event_date From x FULL OUTER JOIN y
> ON x.event_date = y.event_date
> ) innerQ
> WHERE ( innerQ.event_date >= {ts '1980-01-01 00:00:00'} )
> ------------------------
>
> Removing the where clause makes the query run quickly. This seems
> extremely strange because it seems like SQL Server should simply be
> able to take the results of innerQ and discard anything with a date
> that doesn't match. If I instead split the query into two pieces where
> I create a temp table and put innerQ into that and then do the select *
> WHERE (...) from the temp table things work fine.
>
> Any thoughts on what SQL Server might be doing to make things slow and
> how I can fix it?
>
> Thanks,
> -Emin

It sounds like the optimizer is somewhat confused over your query.

It would be interesting to see the actual query plan. You can get that
by running SET SHOWPLAN_TEXT ON and then run the query (and then SET
SHOWPLAN_TEXT OFF).

I agree with Alex, that you could try to write the query the way you
normally would, like this:

SELECT x.event_date
FROM x
LEFT JOIN Y ON y.event_date = x.event_date
WHERE event_date >= '19800101'

HTH,
Gert-Jan

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация