pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Torge <torgato@posteo.de>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Feature request for count_estimate(samplesize) aggregate or SAMPLE keyword
Date: Wed, 31 Aug 2022 21:47:32 -0400
Message-ID: <243115.1661996852@sss.pgh.pa.us> (raw)
In-Reply-To: <0e8b1eb9-97bf-0ddf-a487-ac4e4f6e0186@posteo.de>
References: <0e8b1eb9-97bf-0ddf-a487-ac4e4f6e0186@posteo.de>

Torge <torgato@posteo.de> 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 <condition>;

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





view thread (3+ messages)  latest in thread

Message-ID: <243115.1661996852@sss.pgh.pa.us>
Permalink:  ../243115.1661996852@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/243115.1661996852@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, torgato@posteo.de
  Subject: Re: Feature request for count_estimate(samplesize) aggregate or SAMPLE keyword
  In-Reply-To: <243115.1661996852@sss.pgh.pa.us>
  References: <0e8b1eb9-97bf-0ddf-a487-ac4e4f6e0186@posteo.de> <243115.1661996852@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox