Re: COUNT(*) and index-only scans - Mailing list pgsql-hackers

From Robert Haas
Subject Re: COUNT(*) and index-only scans
Date
Msg-id CA+TgmoaWLFXGk-sJsdsJo-YAh4PPGYopH=ah+uhShjVVBeO20g@mail.gmail.com
Whole thread Raw
In response to Re: COUNT(*) and index-only scans  (Greg Stark <stark@mit.edu>)
List pgsql-hackers
On Wed, Dec 14, 2011 at 6:58 AM, Greg Stark <stark@mit.edu> wrote:
> On Mon, Nov 21, 2011 at 6:43 PM, Robert Haas <robertmhaas@gmail.com> wrote:
>> In buffer fill mode, we scan the index and add matching tuples and
>> their CTIDs to the buffer.  When the buffer is full or the index AM
>> reports that there are no more tuples in the scan, we switch to buffer
>> drain mode.
>
> Instead you could do the two phases concurrently the way tuplesort
> implements the tapesort from Knuth. You keep a heap of ctids with an
> epoch. You fill the heap then you return the first one. Whenever you
> return one you read the next one and add it to the heap. If it falls
> before the last returned value you insert it with the next epoch but
> if it falls afterwards you can insert it into the heap in its correct
> position.

Yeah, that's pretty much what I was imagining, although my explanation
of it was slightly muddled.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


pgsql-hackers by date:

Previous
From: Greg Smith
Date:
Subject: Re: Patch to allow users to kill their own queries
Next
From: Shigeru Hanada
Date:
Subject: Re: pgsql_fdw, FDW for PostgreSQL server