pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Brad Hilton <bhilton@vpop.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: sub-query optimization
Date: Fri, 14 Feb 2003 17:08:27 -0500
Message-ID: <11481.1045260507@sss.pgh.pa.us> (raw)
In-Reply-To: <1045246939.29966.22.camel@aragorn.vpop.net>
References: <1045246939.29966.22.camel@aragorn.vpop.net>

Brad Hilton <bhilton@vpop.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



view thread (14+ messages)  latest in thread

Message-ID: <11481.1045260507@sss.pgh.pa.us>
Permalink:  ../11481.1045260507@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/11481.1045260507@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, bhilton@vpop.net
  Subject: Re: sub-query optimization
  In-Reply-To: <11481.1045260507@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox