From: Arturo Guadagnin <tuirutuiru@gmail.com>
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: inner join elimination
Date: Tue, 29 May 2018 10:30:19 +0200
Message-ID: <5b0d0f9a.1c69fb81.c74b7.a26c@mx.google.com> (raw)
Hi
I was just wondering whether inner join elimination is working in postgres, so I put up a simple test case and compared it with an Oracle database (see output below).
It doesn't look like this feature is implemented in postgres, or am I missig something?
Are there any plans to implement it in the future?
-----------------------------------------
* Oracle 11.2
----------------------------------------
CREATE TABLE m (
i INTEGER NOT NULL,
c VARCHAR(10),
CONSTRAINT m_pk PRIMARY KEY(i)
);
CREATE TABLE c (
i INTEGER NOT NULL,
created_tm DATE NOT NULL,
CONSTRAINT c_pk PRIMARY KEY(i, created_tm),
CONSTRAINT c_m_fk FOREIGN KEY(i) REFERENCES m
);
explain plan for
select c.*
from m
join c
ON (m.i = c.i);
select *
from table(dbms_xplan.display);
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 22 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| C | 1 | 22 | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------
----------------------------------------
* postgres 11-beta
----------------------------------------
CREATE TABLE m (
i INTEGER NOT NULL,
c VARCHAR(10),
CONSTRAINT m_pk PRIMARY KEY(i)
);
CREATE TABLE c (
i INTEGER NOT NULL,
created_tm timestamp NOT NULL,
CONSTRAINT c_pk PRIMARY KEY(i, created_tm),
CONSTRAINT c_m_fk FOREIGN KEY(i) REFERENCES m
);
explain
select c.*
from m
join c
ON (m.i = c.i);
QUERY PLAN
-----------------------------------------------------------------
Hash Join (cost=36.10..92.24 rows=2040 width=12)
Hash Cond: (c.i = m.i)
-> Seq Scan on c (cost=0.00..30.40 rows=2040 width=12)
-> Hash (cost=21.60..21.60 rows=1160 width=4)
-> Seq Scan on m (cost=0.00..21.60 rows=1160 width=4)
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-general@postgresql.org
Cc: tuirutuiru@gmail.com
Subject: Re: inner join elimination
In-Reply-To: <5b0d0f9a.1c69fb81.c74b7.a26c@mx.google.com>
References: <5b0d0f9a.1c69fb81.c74b7.a26c@mx.google.com>
* 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