Re: So, is COUNT(*) fast now?

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jeff Janes <jeff.janes@gmail.com>
Cc: Robert Haas <robertmhaas@gmail.com>, pgsql-hackers@postgresql.org
Date: 2011-10-23T22:04:33Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Remove pg_upgrade dependency on the 'postgres' database existing in the

Jeff Janes <jeff.janes@gmail.com> writes:
> count(*) and sum(1) do different things internally, and in my hands
> sum(1) is ~10% slower.
> I don't know how to dump the output of ExecBuildProjectionInfo into a
> human readable form, so I don't know the basis of the difference.  But
> I wonder if using count(*) would lower the weight of the ExecProject
> function.

Probably.  count() doesn't actually have any arguments, so there's
nothing for ExecProject to do.  sum(1) invokes the generic case there
(ExecTargetList).  I suppose we could add another special-case path for
constant tlist elements, but I suspect that would mostly be optimizing
for benchmarks rather than helping real-world cases.

			regards, tom lane