pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: gcp@sjeng.org
To: pgsql-bugs@postgresql.org
Subject: BUG #12963: WHERE constraints on (INNER) JOIN columns are not propagated to both tables
Date: Sat, 04 Apr 2015 23:21:13 +0000
Message-ID: <20150404232113.2569.93814@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      12963
Logged by:          Gian-Carlo Pascutto
Email address:      gcp@sjeng.org
PostgreSQL version: 9.4.1
Operating system:   Linux
Description:        

The relevant parts of the schema are as follows:

CREATE TABLE matches
(
  seq integer NOT NULL,
  start_time integer NOT NULL,
  <blah>
  CONSTRAINT matches_pkey PRIMARY KEY (seq)
)

CREATE TABLE matches_players
(
  seq integer NOT NULL,
  player_num smallint NOT NULL,
  account_id integer,
  <blah>
  CONSTRAINT matches_players_pkey PRIMARY KEY (seq, player_num),
  CONSTRAINT matches_players_seq_fkey FOREIGN KEY (seq)
      REFERENCES matches (seq) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
)

The following is the EXPLAIN ANALYZE output of 2 queries. 
https://dl.dropboxusercontent.com/u/32496746/postgresql.txt

Because this is an (INNER) JOIN, a WHERE constraint that is given to one
table, on the joined column, applies to the other table as well.
PostgreSQL's query planner does not understand this and consequently
produces a query plan that is a factor 35 slower than when one restates the
constraint.

That is, when given:

        join matches on matches.seq = matches_players.seq 
        where matches.seq > 1151575404 and matches.seq < 1155066769 

there should be no need to add:

        and matches_players.seq > 1151575404 and matches_players.seq <
1155066769;

because this is implied by the JOIN ON.




-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (2+ messages)  latest in thread

Message-ID: <20150404232113.2569.93814@wrigleys.postgresql.org>
Permalink:  ../20150404232113.2569.93814@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20150404232113.2569.93814@wrigleys.postgresql.org

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: gcp@sjeng.org
  Subject: Re: BUG #12963: WHERE constraints on (INNER) JOIN columns are not propagated to both tables
  In-Reply-To: <20150404232113.2569.93814@wrigleys.postgresql.org>
  References: <20150404232113.2569.93814@wrigleys.postgresql.org>

* 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