pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Simon Riggs <simon@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-performance <pgsql-performance@postgresql.org>
Subject: Re: Outer joins and equivalence
Date: Mon, 02 Jun 2008 20:47:11 +0100
Message-ID: <1212436031.4120.400.camel@ebony.site> (raw)
In-Reply-To: <1212426644.4120.378.camel@ebony.site>
References: <1211918358.4489.257.camel@ebony.site>
	<14085.1211924592@sss.pgh.pa.us>
	<1212426644.4120.378.camel@ebony.site>


On Mon, 2008-06-02 at 18:10 +0100, Simon Riggs wrote:
> On Tue, 2008-05-27 at 17:43 -0400, Tom Lane wrote:
> > Simon Riggs <simon@2ndquadrant.com> writes:
> > > I have a complex query where making a small change to the SQL increases
> > > run-time by > 1000 times.
> > 
> > > The first SQL statement is of the form
> > 
> > > A JOIN B ON (a.id = b.id) LEFT JOIN C ON (a.id = c.id) 
> > 
> > > and the second is like this
> > 
> > > A JOIN B ON (a.id = b.id) LEFT JOIN C ON (b.id = c.id)
> > 
> > > the only difference is the substitution of a -> b
> > 
> > Please provide an actual test case.
> 
> Getting closer, but still not able to produce a moveable test case.

I've got a test case which shows something related and weird, though not
the exact case.

The queries shown here have significantly different costs, depending
upon whether we use tables a or b in the query. Since a and b are
equivalent this result isn't expected at all.

I suspect the plan variation in the original post is somehow cost
related and we are unlikely to discover the exact plan.

-- 
 Simon Riggs           www.2ndQuadrant.com
 PostgreSQL Training, Services and Support

Attachments:

q.sql (text/x-sql, 1.4K) download drop table if exists a cascade; create table a (id integer not null primary key ,partition integer ,filler text ); create table a_p1 as select generate_series(1, 10000000)::integer as id, 1::integer as partition, repeat('a',100) as filler; alter table a_p1 add primary key (id); alter table a_p1 inherit a; alter table a_p1 add check ( partition = 1); create table a_p2 as select generate_series(1000000000,1001000000)::integer as id, 2::integer as partition, repeat('a',100) as filler; alter table a_p2 add primary key (id); alter table a_p2 inherit a; alter table a_p2 add check ( partition = 2); drop table if exists b cascade; create table b (id integer not null primary key ,filler text ); drop table if exists c cascade; create table c (id integer not null primary key ,othercol integer ); create index c_idx on c (othercol); insert into c select generate_series(1,24667), 0; insert into c select generate_series(25000, 27488), 1; explain select count(*) from a join b on (a.id = b.id) left join c on (a.id = c.id and c.othercol = 1); explain select count(*) from a join b on (a.id = b.id) left join c on (b.id = c.id and c.othercol = 1); set enable_seqscan = off; explain select count(*) from a join b on (a.id = b.id) left join c on (a.id = c.id and c.othercol = 1); explain select count(*) from a join b on (a.id = b.id) left join c on (b.id = c.id and c.othercol = 1);

view thread (8+ messages)  latest in thread

Message-ID: <1212436031.4120.400.camel@ebony.site>
Permalink:  ../1212436031.4120.400.camel@ebony.site/
Also on:    postgresql.org/message-id/1212436031.4120.400.camel@ebony.site

 · 

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: simon@2ndquadrant.com, tgl@sss.pgh.pa.us
  Subject: Re: Outer joins and equivalence
  In-Reply-To: <1212436031.4120.400.camel@ebony.site>

* 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