is it possible to for the planner to optimize this form?

From: "Merlin Moncure" <merlin(dot)moncure(at)rcsonline(dot)com>
To: <pgsql-performance(at)postgresql(dot)org>
Subject: is it possible to for the planner to optimize this form?
Date: 2004-06-07 17:30:29
Message-ID: 6EE64EF3AB31D5448D0007DD34EEB34101AE56@Herge.rcsinc.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Right now, I am having trouble getting the planner to optimize queries
in the form of

select t.key, t.field from t a
where
(
select count(*) from t b
where b.field > a.field
) = k

The subplan (either index or seq. scan) executes once for each row in t,
which of course takes forever.

This query is a way of achieving LIMIT type results (substitute n-1
desired rows for k) using standard SQL, which is desirable in some
circumstances. Is it theoretically possible for this to be optimized?

Merlin

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Steve Wampler 2004-06-07 17:40:56 Re: [PERFORM] Using a COPY...FROM through JDBC?
Previous Message SZŰCS Gábor 2004-06-07 17:19:06 Re: Relation of cpu_*_costs?