From: Bill Howe <howew@stccmop.org>
To: pgsql-performance@postgresql.org
Subject: index scan through a subquery
Date: Thu, 01 Feb 2007 17:44:21 -0800
Message-ID: <45C29775.3020507@stccmop.org> (raw)
Why should these queries have different plans?
create table foo (a int PRIMARY KEY);
Q1: explain select max(a) from foo
> Result (cost=0.04..0.05 rows=1 width=0)
> InitPlan
> -> Limit (cost=0.00..0.04 rows=1 width=4)
> -> Index Scan Backward using foo_pkey on foo
> (cost=0.00..76.10 rows=2140 width=4)
> Filter: (a IS NOT NULL)
Q2: explain select max(a) from (select * from foo) as f
> Aggregate (cost=36.75..36.76 rows=1 width=4)
> -> Seq Scan on foo (cost=0.00..31.40 rows=2140 width=4)
I need the lovely index scan, but my table is hidden behind a view, and
all I get is the ugly sequential scan. Any ideas on how to convince the
optimizer to unfold the subquery properly?
Bill
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: howew@stccmop.org
Subject: Re: index scan through a subquery
In-Reply-To: <45C29775.3020507@stccmop.org>
* 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