Re: SELECT DISTINCT scans the table?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: SELECT DISTINCT scans the table?
Дата
Msg-id 1238959.1639687677@sss.pgh.pa.us
обсуждение исходный текст
Ответ на SELECT DISTINCT scans the table?  (Markus Demleitner <msdemlei@ari.uni-heidelberg.de>)
Ответы Re: SELECT DISTINCT scans the table?
Список pgsql-general
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



В списке pgsql-general по дате отправления:

Предыдущее
От: Bryn Llewellyn
Дата:
Сообщение: Re: Packages, inner subprograms, and parameterizable anonymous blocks for PL/pgSQL
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: Packages, inner subprograms, and parameterizable anonymous blocks for PL/pgSQL