Re: DISTINCT on jsonb fields and Indexes

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: DISTINCT on jsonb fields and Indexes
Дата
Msg-id 2081356.1592845514@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: DISTINCT on jsonb fields and Indexes  (Michael Lewis <mlewis@entrata.com>)
Ответы Re: DISTINCT on jsonb fields and Indexes  (Michael Lewis <mlewis@entrata.com>)
Список pgsql-general
Michael Lewis <mlewis@entrata.com> writes:
> On Sun, Jun 21, 2020 at 10:43 PM Sankar P <sankar.curiosity@gmail.com>
> wrote:
>> 2) CREATE INDEX idx_btree_records ON fluent USING BTREE ((record ->>
>> 'destinationServiceName'));

> If it is rarely used, create a partial index perhaps. I am a little
> surprised that the plain btree index wasn't used from my naive point of
> view.

It's not terribly surprising unfortunately.  The planner will seldom
recognize that an expression index is good for anything except
searches, that is "WHERE indexed_expression indexable_operator constant".
There's some mention of this at

https://www.postgresql.org/docs/current/indexes-index-only-scans.html

The core of the problem is not wanting to expend cycles on trying to
match every subexpression in the query to every index expression;
so at least in early planning stages, only potentially-indexable
subexpressions of WHERE clauses get matched to indexes.  In the
example of "select distinct expression", the planner will never notice
that that expression has anything to do with an index.

            regards, tom lane



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

Предыдущее
От: Stephen Frost
Дата:
Сообщение: Re: Netapp SnapCenter
Следующее
От: "Jim Hurne"
Дата:
Сообщение: RE: autovacuum failing on pg_largeobject and disk usage of thepg_largeobject growing unchecked