Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iB46V-0008U8-Vv for pgsql-performance@arkaria.postgresql.org; Thu, 19 Sep 2019 21:36:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iB46U-000376-EG for pgsql-performance@arkaria.postgresql.org; Thu, 19 Sep 2019 21:36:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iB46U-00036v-5Q for pgsql-performance@lists.postgresql.org; Thu, 19 Sep 2019 21:36:42 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iB46S-0005TX-1P for pgsql-performance@lists.postgresql.org; Thu, 19 Sep 2019 21:36:41 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x8JLaZWs015292; Thu, 19 Sep 2019 17:36:35 -0400 From: Tom Lane To: Adam Brusselback cc: Thomas Kellerer , pgsql-performance@lists.postgresql.org Subject: Re: Surprising benchmark count(1) vs. count(*) In-reply-to: References: <35f81ca4-f68e-8b71-d34c-7364751b4e36@gmx.net> <22758.1568902312@sss.pgh.pa.us> Comments: In-reply-to Adam Brusselback message dated "Thu, 19 Sep 2019 16:38:33 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <15290.1568928995.1@sss.pgh.pa.us> Date: Thu, 19 Sep 2019 17:36:35 -0400 Message-ID: <15291.1568928995@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Adam Brusselback writes: > It would be nice if Postgres optimized this case though because it is > really really common from what i've seen. Since the introduction of the "planner support function" infrastructure, it'd be possible to do this without it being a completely ugly kluge: we could put the logic for it into a planner support function attached to count(any). Currently planner support functions are only called for regular functions, but we could certainly envision adding the ability to do it for aggregates (and window functions too, why not). I'm not particularly planning to do that myself, but if someone else wants to write a patch, have at it. regards, tom lane