ec_usage_demo.sql

application/sql

Filename: ec_usage_demo.sql
Type: application/sql
Part: 1
Message: Re: Removing unneeded self joins
DROP TABLE IF EXISTS t,t2 CASCADE;
CREATE TABLE t (id int);
CREATE TABLE t2 (id int UNIQUE, x varchar(20), y bigint);
ANALYZE;

EXPLAIN (COSTS OFF)
select b.x,c.y
  from t
   join t2 as b on (b.id = t.id)
      join t2 as c on (c.id = t.id);

/*
 Nested Loop
   Join Filter: (t.id = c.id)
   ->  Seq Scan on t
   ->  Seq Scan on t2 c
         Filter: (id IS NOT NULL)
(5 rows)
*/