pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Maarten Mortier <maarten.mortier@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: "Skipping" BitmapHeapScan for simple counts
Date: Fri, 30 Apr 2021 10:29:12 -0400
Message-ID: <3257726.1619792952@sss.pgh.pa.us> (raw)
In-Reply-To: <CAHX=fuo4Zq0M-s+SX0x1fODbUM+9n+FghZYwkLeyxV1+biF63A@mail.gmail.com>
References: <CAHX=fuo4Zq0M-s+SX0x1fODbUM+9n+FghZYwkLeyxV1+biF63A@mail.gmail.com>

Maarten Mortier <maarten.mortier@gmail.com> writes:
> We have a jsonb_ops GIN index on this field, because we query the following
> "freeform" match:

> SELECT COUNT(id)
> FROM records
> WHERE data @@ '$.**.label == "person"';

> However, in the case of jsonb queries above, there is no need to do the
> BitmapHeapScan really: the BitmapIndexScan has the correct row count,
> always.

This claim is wrong (in general) because of the need to verify visibility
of the heap row.  You might be able to look aside at the visibility map
and find out that a particular heap page is all-visible, but unless the
table is mostly static that can easily be a net waste of cycles.  The
reason we make a distinction between plain indexscans and index-only
scans is to encode in the plan whether the planner thought such checks
were likely to be a win.  To transpose the idea into bitmapscans, you'd
need similar infrastructure, which is not going to be a hack-it-in-one-
place project.

More to the point: I doubt this will help at all for the query above,
because I doubt that the index is lossless for this query.  From what
I recall of GIN for jsonb, what it will return is TIDs for tuples that
contain both "label" and "person".  Whether they have the relationship
of "person" being the value of a "label" tag can't be told without
looking at the actual JSON value.

			regards, tom lane





view thread (2+ messages)

Message-ID: <3257726.1619792952@sss.pgh.pa.us>
Permalink:  ../3257726.1619792952@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3257726.1619792952@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, maarten.mortier@gmail.com
  Subject: Re: "Skipping" BitmapHeapScan for simple counts
  In-Reply-To: <3257726.1619792952@sss.pgh.pa.us>
  References: <CAHX=fuo4Zq0M-s+SX0x1fODbUM+9n+FghZYwkLeyxV1+biF63A@mail.gmail.com> <3257726.1619792952@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