Yang Zhang <yanghatespam(at)gmail(dot)com> writes:
>> # select count(1) from (SELECT * from metarelcould_transactionlog
>> order by transactionid) as foo;
> Does it strike anyone else that the query optimizer/rewriter should be
> able to toss out the sort from such a query altogether?
It could, if it knew that the aggregate function didn't care about input
row order. We don't have that knowledge about aggregates ATM.
regards, tom lane