pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Brad Hilton <bhilton@vpop.net>
To: pgsql-sql@postgresql.org
Subject: Re: sub-query optimization
Date: 14 Feb 2003 10:38:51 -0800
Message-ID: <1045247931.29968.28.camel@aragorn.vpop.net> (raw)
In-Reply-To: <1045246939.29966.22.camel@aragorn.vpop.net>
References: <1045246939.29966.22.camel@aragorn.vpop.net>

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



view thread (14+ messages)  latest in thread

Message-ID: <1045247931.29968.28.camel@aragorn.vpop.net>
Permalink:  ../1045247931.29968.28.camel@aragorn.vpop.net/
Also on:    postgresql.org/message-id/1045247931.29968.28.camel@aragorn.vpop.net

 · 

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: bhilton@vpop.net
  Subject: Re: sub-query optimization
  In-Reply-To: <1045247931.29968.28.camel@aragorn.vpop.net>

* 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