pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Mark kirkwood <markir@slingshot.co.nz>
Cc: pgsql-sql@postgresql.org
Subject: Re: On Differing Optimizer Choices ( Again)
Date: Mon, 03 Sep 2001 18:33:04 -0400
Message-ID: <6848.999556384@sss.pgh.pa.us> (raw)
In-Reply-To: <01082823525200.01374@spikey.slithery.org>
References: <01082823525200.01374@spikey.slithery.org>

Mark kirkwood <markir@slingshot.co.nz> writes (heavily edited):
> SELECT
> ...
> WHERE d0.d0key = f.d0key
> AND   f.d0key BETWEEN 270 AND 350

> So far this is all as one would expect. However suppose we substitute 
> 'd0.d0key' in the 'AND' clause instead of 'f.d0key' to obtain :

> SELECT
> ...
> WHERE d0.d0key = f.d0key
> AND   d0.d0key BETWEEN 270 AND 350

> [ produces a different plan because of differing row-count estimates ]

This surprises me not at all.  While the planner has some rudimentary
grasp of the notion that equality is transitive, that grasp does not
extend as far as recognizing that the above queries are really
equivalent.  You'd probably get a better plan if you wrote out the
entire WHERE condition that you are thinking is intuitively obvious:

SELECT
...
WHERE d0.d0key = f.d0key
AND   d0.d0key BETWEEN 270 AND 350
AND   f0.d0key BETWEEN 270 AND 350

so that the planner could see that there is a range restriction on each
of the tables.

While it'd be possible to teach the planner to deduce the third clause
from the first two, I'm unconvinced that adding such logic would be a
good idea.  It would slow down all queries (probably by quite a bit)
for a benefit that I suspect arises relatively seldom.  Might be worth
looking at this sometime in the future, but...

			regards, tom lane



view thread (2+ messages)  latest in thread

Message-ID: <6848.999556384@sss.pgh.pa.us>
Permalink:  ../6848.999556384@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/6848.999556384@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-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, markir@slingshot.co.nz
  Subject: Re: On Differing Optimizer Choices ( Again)
  In-Reply-To: <6848.999556384@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