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


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Reply via email to