pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Danny Shemesh <dany74q@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Index filter instead of index condition w/ IN / ANY queries above certain set size
Date: Wed, 23 Nov 2022 15:24:40 +0100
Message-ID: <73d1582fec0ef31e1f2e072e979a875cc851eff6.camel@cybertec.at> (raw)
In-Reply-To: <CAFZC=QrNdG+6+K1tWyZTRtiAz6+VG_8hQrnhTYV-Dac2eFaanQ@mail.gmail.com>
References: <CAFZC=QoOTo4gYBA-gDz-XJejfBZVfgy3VZV7zpQc6T4C+3Yf+g@mail.gmail.com>
	<df2e15e9b4d5d72ce2e6a6dc65eb8dc529cee8d8.camel@cybertec.at>
	<CAFZC=QrNdG+6+K1tWyZTRtiAz6+VG_8hQrnhTYV-Dac2eFaanQ@mail.gmail.com>

On Wed, 2022-11-23 at 15:38 +0200, Danny Shemesh wrote:
> ->  Limit  (cost=0.56..24.17 rows=1 width=16) (actual time=2657.167..2657.167 rows=1 loops=39)
>       Buffers: shared hit=323452 read=887661
>       I/O Timings: read=2369932.536
>       ->  Index Only Scan using idx_hashes on refs refs_1  (cost=0.56..265306.68 rows=11238 width=16) (actual time=2657.162..2657.162 rows=1 loops=39)
>             Index Cond: ((tid = '13371337-1337-1337-1337-133713371337'::uuid) AND (pidh > cte_1.pidh))
>             Filter: (tidh = ANY ('{13391339-1339-1339-1339-133913391339}'::uuid[]))    <<<<<<<<<<<<<<<- Note this line
>             Rows Removed by Filter: 346024
>             Heap Fetches: 1506359
>             Buffers: shared hit=323452 read=887661
>             I/O Timings: read=2369932.536

PostgreSQL thinks that there are enough such rows that it is cheaper to use the index
that supports the ORDER BY.  I don't know why there is a difference between = ANY
and = here, but you can use an expression like "ORDER BY pidh + 0" to avoid that.

Yours,
Laurenz Albe





view thread (6+ messages)  latest in thread

Message-ID: <73d1582fec0ef31e1f2e072e979a875cc851eff6.camel@cybertec.at>
Permalink:  ../73d1582fec0ef31e1f2e072e979a875cc851eff6.camel@cybertec.at/
Also on:    postgresql.org/message-id/73d1582fec0ef31e1f2e072e979a875cc851eff6.camel@cybertec.at

 · 

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: laurenz.albe@cybertec.at, dany74q@gmail.com
  Subject: Re: Index filter instead of index condition w/ IN / ANY queries above certain set size
  In-Reply-To: <73d1582fec0ef31e1f2e072e979a875cc851eff6.camel@cybertec.at>
  References: <CAFZC=QoOTo4gYBA-gDz-XJejfBZVfgy3VZV7zpQc6T4C+3Yf+g@mail.gmail.com> <df2e15e9b4d5d72ce2e6a6dc65eb8dc529cee8d8.camel@cybertec.at> <CAFZC=QrNdG+6+K1tWyZTRtiAz6+VG_8hQrnhTYV-Dac2eFaanQ@mail.gmail.com> <73d1582fec0ef31e1f2e072e979a875cc851eff6.camel@cybertec.at>

* 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