Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Yf7sq-0000uG-92 for pgsql-bugs@arkaria.postgresql.org; Mon, 06 Apr 2015 14:20:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Yf7sp-0003WF-7l for pgsql-bugs@arkaria.postgresql.org; Mon, 06 Apr 2015 14:20:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YeXOG-0003db-Iq for pgsql-bugs@postgresql.org; Sat, 04 Apr 2015 23:22:12 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YeXO7-0000IC-Hl for pgsql-bugs@postgresql.org; Sat, 04 Apr 2015 23:22:11 +0000 MIME-Version: 1.0 Subject: BUG #12963: WHERE constraints on (INNER) JOIN columns are not propagated to both tables To: pgsql-bugs@postgresql.org From: gcp@sjeng.org Date: Sat, 04 Apr 2015 23:21:13 +0000 Message-ID: <20150404232113.2569.93814@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.9 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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, CONSTRAINT matches_pkey PRIMARY KEY (seq) ) CREATE TABLE matches_players ( seq integer NOT NULL, player_num smallint NOT NULL, account_id integer, 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