Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTZIv-000337-Hk for pgsql-general@arkaria.postgresql.org; Thu, 01 Sep 2022 01:47:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oTZIu-0006EA-EN for pgsql-general@arkaria.postgresql.org; Thu, 01 Sep 2022 01:47:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTZIu-0006Dg-3i for pgsql-general@lists.postgresql.org; Thu, 01 Sep 2022 01:47:36 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTZIr-0002ud-Uy for pgsql-general@lists.postgresql.org; Thu, 01 Sep 2022 01:47:35 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 2811lWbu243116; Wed, 31 Aug 2022 21:47:32 -0400 From: Tom Lane To: Torge cc: pgsql-general@lists.postgresql.org Subject: Re: Feature request for count_estimate(samplesize) aggregate or SAMPLE keyword In-reply-to: <0e8b1eb9-97bf-0ddf-a487-ac4e4f6e0186@posteo.de> References: <0e8b1eb9-97bf-0ddf-a487-ac4e4f6e0186@posteo.de> Comments: In-reply-to Torge message dated "Thu, 01 Sep 2022 01:07:09 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <243114.1661996852.1@sss.pgh.pa.us> Date: Wed, 31 Aug 2022 21:47:32 -0400 Message-ID: <243115.1661996852@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Torge writes: > Now I would like to humbly propose a feature that gives an easy way to > get a quick count estimate for any condition - index based or not - > based on a random sample of rows, that does not require a custom > function creation or complex SQL statement Can't you do that already using TABLESAMPLE? For example, to use a 1% sample: select count(*) * 100 from mytab tablesample system(1) where ; You do have to remember to multiply by the factor corresponding to your sample rate, but aside from that annoyance this (a) already exists, (b) is SQL-standard, and (c) can be adapted to a lot of other kinds of analysis besides plain count(*). regards, tom lane