Re: GIN JSONB path index is not always used

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Tomasz Szymański <lime129(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: GIN JSONB path index is not always used
Date: 2023-10-23 14:05:01
Message-ID: CAMkU=1ymeq5bdJD7d0jDr+tALSXTuvtDR9Jmfx6Hq7yS00qzCA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Mon, Oct 23, 2023 at 6:33 AM Tomasz Szymański <lime129(at)gmail(dot)com> wrote:

> Limit (cost=0.00..1184.30 rows=21 width=4) (actual
> time=1567.136..1619.956 rows=1 loops=1)
> -> Seq Scan on account_user (cost=0.00..256768.27 rows=4553 width=4)
> (actual time=1567.135..1619.953 rows=1 loops=1)
>

It thinks the seq scan will stop 99.5% early, after finding 21 out of 4553
qualifying tuples. But instead it has to read the entire table to actually
find only 1.

The selectivity estimate of the @> operator has been substantially improved
in v13. It is still far from perfect, but should be good enough to solve
this problem for this case and most similar cases. Turning off fastupdate
on the index would probably also solve the problem, for a different reason.

Cheers,

Jeff

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Alexander Okulovich 2023-10-26 13:47:03 Re: Postgres 15 SELECT query doesn't use index under RLS
Previous Message Tomasz Szymański 2023-10-23 10:33:46 Re: GIN JSONB path index is not always used