pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: PFC <lists@peufeu.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Interesting slow query
Date: Mon, 12 Jun 2006 18:53:08 -0400
Message-ID: <13392.1150152788@sss.pgh.pa.us> (raw)
In-Reply-To: <op.ta1s0auacigqcu@apollo13>
References: <003601c687ce$7aee7b20$7f00a8c0@kicommunication.com>
	<op.ta1s0auacigqcu@apollo13>

PFC <lists@peufeu.com> writes:
> 	Here are two ways to phrase a query... the planner choses very different  
> plans as you will see. Everything is freshly ANALYZEd.

Usually we get complaints the other way around (that the NOT EXISTS
approach is a lot slower).  You did not show any statistics, but I
suspect the key point here is that the condition id > 1130306 excludes
most or all of the A and D tables.  The planner is not smart about
making transitive inequality deductions, but you could help it along
by adding the implied clauses yourself:

EXPLAIN ANALYZE SELECT r.* FROM raw_annonces r
  LEFT JOIN annonces a ON (a.id=r.id AND a.id > 1130306)
  LEFT JOIN archive_data d ON (d.id=r.id AND d.id > 1130306)
  WHERE a.id IS NULL AND d.id IS NULL AND r.id > 1130306
  order by id limit 1;

Whether this is worth doing in your app depends on how often you do
searches at the end of the ID range ...

			regards, tom lane



view thread (3+ messages)  latest in thread

Message-ID: <13392.1150152788@sss.pgh.pa.us>
Permalink:  ../13392.1150152788@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/13392.1150152788@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-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, lists@peufeu.com
  Subject: Re: Interesting slow query
  In-Reply-To: <13392.1150152788@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