pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Brad Hilton <bhilton@vpop.net>
To: jasiek@serwer.skawsoft.com.pl
Cc: pgsql-sql@postgresql.org
Subject: Re: sub-query optimization
Date: 14 Feb 2003 11:42:27 -0800
Message-ID: <1045251747.29974.45.camel@aragorn.vpop.net> (raw)
In-Reply-To: <20030214192113.GA26987@serwer>
References: <1045246939.29966.22.camel@aragorn.vpop.net>
	<20030214192113.GA26987@serwer>

On Fri, 2003-02-14 at 11:21, jasiek@serwer.skawsoft.com.pl wrote:

> Can you test these two queries?

Thanks, I'll test them shortly.  I wanted to answer your other
questions, first:


>  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?

Sorry to cause confusion.  My original query and db format were fairly
complex so I didn't want to distract from my problem.  My actual query
looks like:

select * from articles where exists
  (select 1 from article_categories, categories, category_map
   where
   article_categories.article_id = articles.id and
   categories.restrict_views = FALSE and
   article_categories.category_id = categories.id and
   category_map.parent_id = 1 and
   category_map.child_id = categories.id and
   category_map.child_id = article_categories.category_id and
   articles.post_status = 'publish'
  )
 and
post_status = 'publish'

------------------
The problem is that sometimes there are no categories with
"restrict_views = FALSE" and the query takes a *long* time: 23 seconds. 
However, if I simply add the 'articles' table to the inner query it
takes 0.23 msec.

*But*, sometimes there are many categories where "restrict_views =
FALSE", and in such a case adding the 'articles' table to the inner
query actually hurts performance quite a bit.

Does that help at all?

Thanks,
-Brad



view thread (14+ messages)  latest in thread

Message-ID: <1045251747.29974.45.camel@aragorn.vpop.net>
Permalink:  ../1045251747.29974.45.camel@aragorn.vpop.net/
Also on:    postgresql.org/message-id/1045251747.29974.45.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, jasiek@serwer.skawsoft.com.pl
  Subject: Re: sub-query optimization
  In-Reply-To: <1045251747.29974.45.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