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 18:00:54 -0400
Message-ID: <2093791.1592863254@sss.pgh.pa.us> (raw)
In-Reply-To: <CAHOFxGoMiX+Vc=E_t5yxaWZbe2+cbU-68bWJYge_AB+foVfDTw@mail.gmail.com>
References: <CAMSEaH6ri7hH3-MywK+Vrb=RpkhzMufU2xXFdSKV9zubmniieg@mail.gmail.com>
	<CAHOFxGpWgy4PC0MczyWHK6UTgc-RxO_RS0cezLChkH+Tksbk-A@mail.gmail.com>
	<2081356.1592845514@sss.pgh.pa.us>
	<CAHOFxGoMiX+Vc=E_t5yxaWZbe2+cbU-68bWJYge_AB+foVfDTw@mail.gmail.com>

Michael Lewis <mlewis@entrata.com> writes:
>> In the example of "select distinct expression", the planner will never
>> notice that that expression has anything to do with an index.

> Thanks for that explanation. I assume re-writing as a 'group by' would have
> no bearing on that planner decision.

Hmm ... actually, now that you mention it, it might.  Using GROUP BY
moves the expression into the category of "things we might want to
sort on", and we do pay attention to indexes for that.  Trying it
just now, I find that I can get a index scan but not an index-only
scan for something like "select expr from tab group by expr".
Not sure if that will move the needle enough to help for the
original problem.

			regards, tom lane





view thread (8+ messages)

Message-ID: <2093791.1592863254@sss.pgh.pa.us>
Permalink:  ../2093791.1592863254@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2093791.1592863254@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: <2093791.1592863254@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> <CAHOFxGoMiX+Vc=E_t5yxaWZbe2+cbU-68bWJYge_AB+foVfDTw@mail.gmail.com> <2093791.1592863254@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