pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Michael Lewis <mlewis@entrata.com>
Cc: Sankar P <sankar.curiosity@gmail.com>
Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>
Subject: Re: DISTINCT on jsonb fields and Indexes
Date: Mon, 22 Jun 2020 13:05:14 -0400
Message-ID: <2081356.1592845514@sss.pgh.pa.us> (raw)
In-Reply-To: <CAHOFxGpWgy4PC0MczyWHK6UTgc-RxO_RS0cezLChkH+Tksbk-A@mail.gmail.com>
References: <CAMSEaH6ri7hH3-MywK+Vrb=RpkhzMufU2xXFdSKV9zubmniieg@mail.gmail.com>
	<CAHOFxGpWgy4PC0MczyWHK6UTgc-RxO_RS0cezLChkH+Tksbk-A@mail.gmail.com>

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





view thread (8+ messages)  latest in thread

Message-ID: <2081356.1592845514@sss.pgh.pa.us>
Permalink:  ../2081356.1592845514@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2081356.1592845514@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, mlewis@entrata.com, sankar.curiosity@gmail.com
  Subject: Re: DISTINCT on jsonb fields and Indexes
  In-Reply-To: <2081356.1592845514@sss.pgh.pa.us>
  References: <CAMSEaH6ri7hH3-MywK+Vrb=RpkhzMufU2xXFdSKV9zubmniieg@mail.gmail.com> <CAHOFxGpWgy4PC0MczyWHK6UTgc-RxO_RS0cezLChkH+Tksbk-A@mail.gmail.com> <2081356.1592845514@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