From: Tom Lane <tgl@sss.pgh.pa.us>
To: Markus Demleitner <msdemlei@ari.uni-heidelberg.de>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: SELECT DISTINCT <constant> scans the table?
Date: Thu, 16 Dec 2021 15:47:57 -0500
Message-ID: <1238959.1639687677@sss.pgh.pa.us> (raw)
In-Reply-To: <20211216110014.27xcbjfs2rkpjz7t@victor>
References: <20211216110014.27xcbjfs2rkpjz7t@victor>
Markus Demleitner <msdemlei@ari.uni-heidelberg.de> writes:
> Maximally stripped down, my problem is that
> select distinct 300 from <bigtable>
> seqscans <bigtable> (at least in PostgreSQL 11.14). To me, it seems
> obvious that this ought be be just one row containing 300 once
> Postgres has established that <bigtable> is nonempty.
> Why do things not work like this? Am I missing something major?
That seems like the sort of optimization that we absolutely should
not spend cycles looking for. If it were a trivial change consuming
no detectable number of planning cycles, maybe it would be worth the
development and maintenance effort; though I'd be dubious about the
value. But the fact that it'd have to be transformed into something
testing whether the table is nonempty makes it fairly nontrivial.
I doubt it's worth the development cost plus the cycles imposed
on every other query.
regards, tom lane
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, msdemlei@ari.uni-heidelberg.de
Subject: Re: SELECT DISTINCT <constant> scans the table?
In-Reply-To: <1238959.1639687677@sss.pgh.pa.us>
References: <20211216110014.27xcbjfs2rkpjz7t@victor> <1238959.1639687677@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