Re: join removal

Pavel Stehule <pavel.stehule@gmail.com>

From: Pavel Stehule <pavel.stehule@gmail.com>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Greg Stark <stark@mit.edu>, "<pgsql-hackers@postgresql.org>" <pgsql-hackers@postgresql.org>
Date: 2010-03-29T08:19:37Z
Lists: pgsql-hackers
Hello

is any reason why join removal doesn't remove useless relation b?

postgres=# \d a
       Table "public.a"
 Column |  Type   | Modifiers
--------+---------+-----------
 a      | integer |
Indexes:
    "a_a_idx" UNIQUE, btree (a)

postgres=# \d b
       Table "public.b"
 Column |  Type   | Modifiers
--------+---------+-----------
 b      | integer |
Indexes:
    "b_b_idx" UNIQUE, btree (b)

postgres=# explain select  a from a left join b on true;
                            QUERY PLAN
-------------------------------------------------------------------
 Nested Loop Left Join  (cost=0.00..72074.00 rows=5760000 width=4)
   ->  Seq Scan on a  (cost=0.00..34.00 rows=2400 width=4)
   ->  Materialize  (cost=0.00..46.00 rows=2400 width=0)
         ->  Seq Scan on b  (cost=0.00..34.00 rows=2400 width=0)
(4 rows)

postgres=# explain select distinct a from a left join b on true;
                                   QUERY PLAN
---------------------------------------------------------------------------------
 Unique  (cost=0.00..86520.25 rows=2400 width=4)
   ->  Nested Loop Left Join  (cost=0.00..72120.25 rows=5760000 width=4)
         ->  Index Scan using a_a_idx on a  (cost=0.00..80.25 rows=2400 width=4)
         ->  Materialize  (cost=0.00..46.00 rows=2400 width=0)
               ->  Seq Scan on b  (cost=0.00..34.00 rows=2400 width=0)
(5 rows)

Regards
Pavel Stehule