Greg Stark <gsstark(at)mit(dot)edu> writes:
> Last I heard the reason count(*) was so expensive was because its state
> variable was a bigint. That means it doesn't fit in a Datum and has to be
> alloced and stored as a pointer. And because of the Aggregate API that means
> it has to be allocated and freed for every tuple processed.
There's a hack in 8.1 to avoid the palloc overhead (courtesy of Neil
Conway IIRC).
regards, tom lane