On Fri, 2003-02-14 at 10:22, Brad Hilton wrote:
> Hello,
>
> I am hoping someone can help explain why modifying the following query
> can effect such a huge change in speed. The query is:
>
> select * from articles
> where exists
> ( select 1 from article_categories
> where
> article_categories.article_id = articles.id and
> article_categories.category_id is null
> )
To add one more detail: in simplifying my query for the list, I should
have said:
article_categories.category_id = 0
instead of
article_categories.category_id is NULL
Then, with an index on article_categories (category_id) you get the
following results for the two queries:
Without adding the "articles" table to the inner query: 1329 msec
With the "articles" table in the inner query: 0.28 msec!
That highlights the difference a bit more dramatically.
Any ideas?
Thanks,
-Brad