From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Brad Hilton <bhilton(at)vpop(dot)net> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: sub-query optimization |
Date: | 2003-02-14 22:08:27 |
Message-ID: | 11481.1045260507@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Brad Hilton <bhilton(at)vpop(dot)net> writes:
> 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
> )
> ... If I modify the query slightly:
> --------
> select 1 from article_categories
> -->
> select 1 from articles, article_categories
> ---------
> the query takes 98 msec.
Yeah, because then the sub-query is a constant (it doesn't depend on the
current outer row at all) and so it is only evaluated once, not once per
outer row. Unfortunately, that approach probably gives the wrong
answers...
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Brad Hilton | 2003-02-14 22:26:18 | Re: sub-query optimization |
Previous Message | STashlitsky | 2003-02-14 21:33:09 | convert from an integer to a date |