From: Tom Lane <tgl@sss.pgh.pa.us>
To: balasubramanian c r <crbs.siebel@gmail.com>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: GIN INdex is not used with && operator for a text array index
Date: Wed, 06 Dec 2023 09:58:38 -0500
Message-ID: <1099787.1701874718@sss.pgh.pa.us> (raw)
In-Reply-To: <CANnzXMPHcGyv1v5J+jcJyP6hUwd2O7ZLA6yjQJxx332Ou+m63w@mail.gmail.com>
References: <CANnzXMPHcGyv1v5J+jcJyP6hUwd2O7ZLA6yjQJxx332Ou+m63w@mail.gmail.com>
balasubramanian c r <crbs.siebel@gmail.com> writes:
> when Operator '@>' is used the index is used and the execution time is 60ms.
Yeah ... note that it's predicted to return just one row, and that
guess is correct:
> Bitmap Heap Scan on public.address18 (cost=261.25..262.52 rows=1 width=4)
> (actual time=58.992..58.994 rows=1 loops=1)
> when Operator '&&' is used the index is used and the execution time is 60ms.
> It is performing sequential scan which is not expected.
I do not see why you expect that. This case retrieves many more rows
than the other one, both in the planner's estimate and in reality:
> Seq Scan on public.address18 (cost=0.00..77215.11 rows=247741 width=4)
> (actual time=0.063..1880.467 rows=247741 loops=1)
An indexscan is not necessarily better than a seqscan for such cases...
> When i disable the sequential scan the execution time is increased
> significantly.
... so, indeed, the planner was correct to use a seqscan.
> Not expecting this behavior currently.
Your expectation is faulty.
regards, tom lane
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, crbs.siebel@gmail.com
Subject: Re: GIN INdex is not used with && operator for a text array index
In-Reply-To: <1099787.1701874718@sss.pgh.pa.us>
References: <CANnzXMPHcGyv1v5J+jcJyP6hUwd2O7ZLA6yjQJxx332Ou+m63w@mail.gmail.com> <1099787.1701874718@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