Mark Kirkwood <markir@xxxxxxxxxxxxxxx> writes: > Yeah - it's pretty clear that the count aggregate is fairly expensive wrt cpu - > However, I am not sure if all agg nodes suffer this way (guess we could try a > trivial aggregate that does nothing for all tuples bar the last and just > reports the final value it sees). As you mention count(*) and count(1) are the same thing. 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 was some talk of having a special case API for count(*) and maybe sum(...) to avoid having to do this. There was also some talk of making Datum 8 bytes wide on platforms where that was natural (I guess AMD64, Sparc64, Alpha, Itanic). Afaik none of these items have happened but I don't know for sure. -- greg