From: Tomasz Myrta <jasiek@klaster.net>
To: Brad Hilton <bhilton@vpop.net>
To: pgsql-sql@postgresql.org
Subject: Re: sub-query optimization
Date: Fri, 14 Feb 2003 20:24:45 +0800
Message-ID: <20030214202445.M57741@klaster.net> (raw)
In-Reply-To: <1045246939.29966.22.camel@aragorn.vpop.net>
References: <1045246939.29966.22.camel@aragorn.vpop.net>
> 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
> )
>
Can you test these two queries?
select * from
(select article_id from article_categories where category_id is null
group by article_id) X
join articles using (article_id);
select <fields> from
article_categories
join articles using (article_id)
where category_id is null
group by <fields>
Above queries will need index on article_id
I'm not sure if it helps, but they are the only solutions in my
mind ;-)
Can you say anything about data statistics in your tables? How
many rows are with category_id=null?
I looked into query definition once again. Your query doesn't make
sense - article_categories have not null category_id... What do you really
want to do?
Regards,
Tomasz Myrta
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: jasiek@klaster.net, bhilton@vpop.net
Subject: Re: sub-query optimization
In-Reply-To: <20030214202445.M57741@klaster.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