Crazy query plan. - Mailing list pgsql-bugs

From Oleg Serov
Subject Crazy query plan.
Date
Msg-id cec7c6df0911130325q3df937cel9cbec500179f7a5a@mail.gmail.com
Whole thread Raw
Responses Re: Crazy query plan.  (Craig Ringer <craig@postnewspapers.com.au>)
List pgsql-bugs
SQL:
CREATE TABLE test (id BIGINT, id2 BIGINT, id3 BIGINT, id4 BIGINT);
INSERT INTO test SELECT i, i, i, i FROM generate_series(0, 9) i;
EXPLAIN ANALYZE SELECT ((SELECT tmp::test FROM (SELECT * FROM test
LIMIT 1) tmp)::test).*;

WILL:
QUERY PLAN
Result  (cost=0.11..0.12 rows=1 width=0) (actual time=0.076..0.078
rows=1 loops=1)
  InitPlan
    ->  Subquery Scan tmp  (cost=0.00..0.03 rows=1 width=32) (actual
time=0.014..0.019 rows=1 loops=1)
          ->  Limit  (cost=0.00..0.02 rows=1 width=32) (actual
time=0.008..0.009 rows=1 loops=1)
                ->  Seq Scan on test  (cost=0.00..23.10 rows=1310
width=32) (actual time=0.005..0.005 rows=1 loops=1)
    ->  Subquery Scan tmp  (cost=0.00..0.03 rows=1 width=32) (actual
time=0.008..0.013 rows=1 loops=1)
          ->  Limit  (cost=0.00..0.02 rows=1 width=32) (actual
time=0.005..0.006 rows=1 loops=1)
                ->  Seq Scan on test  (cost=0.00..23.10 rows=1310
width=32) (actual time=0.002..0.002 rows=1 loops=1)
    ->  Subquery Scan tmp  (cost=0.00..0.03 rows=1 width=32) (actual
time=0.008..0.012 rows=1 loops=1)
          ->  Limit  (cost=0.00..0.02 rows=1 width=32) (actual
time=0.005..0.006 rows=1 loops=1)
                ->  Seq Scan on test  (cost=0.00..23.10 rows=1310
width=32) (actual time=0.003..0.003 rows=1 loops=1)
    ->  Subquery Scan tmp  (cost=0.00..0.03 rows=1 width=32) (actual
time=0.009..0.013 rows=1 loops=1)
          ->  Limit  (cost=0.00..0.02 rows=1 width=32) (actual
time=0.005..0.006 rows=1 loops=1)
                ->  Seq Scan on test  (cost=0.00..23.10 rows=1310
width=32) (actual time=0.002..0.002 rows=1 loops=1)
Total runtime: 0.138 ms

One subquery for each column. wtf?

pgsql-bugs by date:

Previous
From: Teodor Sigaev
Date:
Subject: Re: BUG #5183: Wrong select results using multicolumn gin indexes
Next
From: Robert Haas
Date:
Subject: Re: BUG #5184: default tablespace owner is not dumped