Skip site navigation (1) Skip section navigation (2)

Re: COUNT(*) and index-only scans

From: Greg Stark <stark(at)mit(dot)edu>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Thom Brown <thom(at)linux(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jeff Davis <pgsql(at)j-davis(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COUNT(*) and index-only scans
Date: 2011-12-14 11:58:59
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
On Mon, Nov 21, 2011 at 6:43 PM, Robert Haas <robertmhaas(at)gmail(dot)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


In response to


pgsql-hackers by date

Next:From: Pavan DeolaseeDate: 2011-12-14 12:20:37
Subject: Re: Race condition in HEAD, possibly due to PGPROC splitup
Previous:From: Peter GeogheganDate: 2011-12-14 11:28:00
Subject: Re: pg_dump --exclude-table-data

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group