Re: Optimize SQL - Mailing list pgsql-performance

From Arjen van der Meijden
Subject Re: Optimize SQL
Date
Msg-id 450AD35F.3070305@tweakers.net
Whole thread Raw
In response to Re: Optimize SQL  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-performance
On 15-9-2006 17:53 Tom Lane wrote:
> If that WHERE logic is actually what you need, then getting this query
> to run quickly seems pretty hopeless.  The database must form the full
> outer join result: it cannot discard any listing0_ rows, even if they
> have lastupdate outside the given range, because they might join to
> addressval2_ rows within the given createdate range.  And conversely
> it can't discard any addressval2_ rows early.  Is there any chance
> that you wanted AND not OR there?

Couldn't it also help to do something like this?

SELECT ..., (SELECT MAX(createdate) FROM addressval ...)
FROM listing l
   LEFT JOIN address ...
WHERE l.id IN (SELECT id FROM listing WHERE lastupdate ...
       UNION
         SELECT id FROM listing JOIN addressval a ON ... WHERE
a.createdate ...)


Its not pretty, but looking at the explain only a small amount of
records match both clauses. So this should allow the use of indexes for
both the createdate-clause and the lastupdate-clause.

Best regards,

Arjen

pgsql-performance by date:

Previous
From: Tom Lane
Date:
Subject: Re: Why the difference in plans ??
Next
From: "Bucky Jordan"
Date:
Subject: Re: RAID 0 not as fast as expected