Re: Optimize ORDER BY ... LIMIT - Mailing list pgsql-hackers

From Gregory Stark
Subject Re: Optimize ORDER BY ... LIMIT
Date
Msg-id 87irjposep.fsf@enterprisedb.com
Whole thread Raw
In response to Re: Optimize ORDER BY ... LIMIT  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Optimize ORDER BY ... LIMIT  (Alvaro Herrera <alvherre@commandprompt.com>)
List pgsql-hackers
Tom Lane <tgl@sss.pgh.pa.us> writes:

> I believe a better way to think about this would be as an aggregate that
> remembers the top N rows.  

Wouldn't such a thing just be a reimplementation of a tuplestore though? I
mean, it's storing tuples you feed it, sorting them, and spitting them back
out in sorted order.

What would you do if the set of tuples turned out to be larger than you
expected and not fit in memory? Create a tuplesort and pass them on to it?

I've already looked at tuplesort and the changes there are minimal. The hard
part is what to do in the planner and executor to get the information to the
tuplestore. Do we want the plan to look the way it does now or use some new
sort of node that consolidates the limit and the sort in the same place.

--  Gregory Stark EnterpriseDB          http://www.enterprisedb.com


pgsql-hackers by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: Reducing data type space usage
Next
From: Martijn van Oosterhout
Date:
Subject: Re: Optimize ORDER BY ... LIMIT