Another planner/optimizer question...

From: Philip Warner <pjw(at)rhyme(dot)com(dot)au>
To: "PGSQL hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Another planner/optimizer question...
Date: 2001-11-01 04:16:06
Message-ID: 3.0.5.32.20011101151606.03866c80@mail.rhyme.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Once again, a slightly convoluted question, but it seems that PG may be
doing a little more work than is necessary when selecting from views with
sub-selects. It seems that every time a view field is being referenced in
an outer select expression, the view field is being re-evaluated. Is there
any way to get PG to know that it only needs to do the aggregate once?

eg.

create table b(f1 int, f2 int);
create table r(f1 int);

create view bv as select f1,f2,
exists(select * from r where r.f1=b.f1) as has_f1,
exists(select * from r where r.f1=b.f2) as has_f2
from b;

explain select f1,f2,
case when has_f1 and has_f2 then 'both'
when has_f1 then 'f1_only'
when has_f2 then 'f2_only'
else 'none'
end as status
from bv;

Seq Scan on b (cost=0.00..20.00 rows=1000 width=8)
SubPlan
-> Seq Scan on r (cost=0.00..22.50 rows=5 width=4)
-> Seq Scan on r (cost=0.00..22.50 rows=5 width=4)
-> Seq Scan on r (cost=0.00..22.50 rows=5 width=4)
-> Seq Scan on r (cost=0.00..22.50 rows=5 width=4)

----------------------------------------------------------------
Philip Warner | __---_____
Albatross Consulting Pty. Ltd. |----/ - \
(A.B.N. 75 008 659 498) | /(@) ______---_
Tel: (+61) 0500 83 82 81 | _________ \
Fax: (+61) 0500 83 82 82 | ___________ |
Http://www.rhyme.com.au | / \|
| --________--
PGP key available upon request, | /
and from pgp5.ai.mit.edu:11371 |/

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2001-11-01 05:28:25 Re: user authentication crash by Erik Luke (20-08-2001; 1.3kb)
Previous Message Denis Perchine 2001-10-31 18:26:10 Re: Serious performance problem