pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
To: Stephen Frost <sfrost@snowman.net>
To: Soni M <diptatapa@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Postgres Bug <pgsql-bugs@postgresql.org>
Subject: Re: Scanning all partition when more than 100 items in "where id in ()" clause
Date: Fri, 27 Jul 2018 18:21:13 +0900
Message-ID: <99ac127f-d5b4-961f-08c2-a2da4be701f7@lab.ntt.co.jp> (raw)
In-Reply-To: <5c46f111-81a8-3156-016e-2b70d6985b4d@lab.ntt.co.jp>
References: <20180727022353.GJ27724@tamriel.snowman.net>
	<5c46f111-81a8-3156-016e-2b70d6985b4d@lab.ntt.co.jp>

On 2018/07/27 17:57, Amit Langote wrote:
> Fwiw, on the tiny machine I work on, attempting pruning with 100-item list
> takes way longer than it takes the planner to just forget about pruning
> and create a plan for all partitions.  But that's just about the planning
> time.

[ ... ]

> -- 101-item list disabling pruning
> explain analyze select * from lt where b in
> (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
> 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
> 
>                                              QUERY PLAN
> 
> 
> 
> ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
> ─────────────────────────────────────────────────────────────────────────────────────
>  Append  (cost=0.29..4463.78 rows=51360 width=8) (actual
> time=0.172..141.214 rows=10000 loops=1)
>    ->  Index Scan using lt_1_b_idx on lt_1  (cost=0.29..438.78 rows=5136
> width=8) (actual time=0.153..55.516 rows=10000 loops=1)
>          Index Cond: (b = ANY
> ('{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
> 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}'::integer[]))
>    ->  Index Scan using lt_2_b_idx on lt_2  (cost=0.29..442.78 rows=5136
> width=8) (actual time=0.091..0.091 rows=0 loops=1)
>          Index Cond: (b = ANY
> ('{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
> 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}'::integer[]))
>    ->  Index Scan using lt_3_b_idx on lt_3  (cost=0.29..446.78 rows=5136
> width=8) (actual time=0.090..0.090 rows=0 loops=1)
>          Index Cond: (b = ANY
> ('{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
> 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}'::integer[]))
> 
> [ Index Scan nodes of remaining patitions ]
> 
>  Planning time: 7.146 ms
>  Execution time: 184.115 ms
> (23 rows)
> 
> Oddly, that seems exactly the opposite of what OP is seeing.

When I tried this again, the planning time for the 101-item list case shot
up.  Not sure what had gone wrong in the previous try.

explain analyze select * from lt where b in
(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);

                                             QUERY PLAN



─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
─────────────────────────────────────────────────────────────────────────────────────
 Append  (cost=0.29..2021.75 rows=10009 width=8) (actual
time=0.104..137.582 rows=10000 loops=1)
   ->  Index Scan using lt_1_b_idx on lt_1  (cost=0.29..403.78 rows=10000
width=8) (actual time=0.094..55.329 rows=10000 loops=1)
         Index Cond: (b = ANY
('{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}'::integer[]))
   ->  Index Scan using lt_2_b_idx on lt_2  (cost=0.29..177.55 rows=1
width=8) (actual time=0.093..0.093 rows=0 loops=1)
         Index Cond: (b = ANY
('{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}'::integer[]))
   ->  Index Scan using lt_3_b_idx on lt_3  (cost=0.29..173.55 rows=1
width=8) (actual time=0.045..0.045 rows=0 loops=1)
         Index Cond: (b = ANY
('{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}'::integer[]))

[ Index Scan nodes of remaining patitions ]

 Planning time: 63.100 ms
 Execution time: 178.995 ms
(23 rows)

So yes, attempting pruning would've helped the 101-item case just as much
as it does the 100-item case.

Thanks,
Amit





view thread (6+ messages)

Message-ID: <99ac127f-d5b4-961f-08c2-a2da4be701f7@lab.ntt.co.jp>
Permalink:  ../99ac127f-d5b4-961f-08c2-a2da4be701f7@lab.ntt.co.jp/
Also on:    postgresql.org/message-id/99ac127f-d5b4-961f-08c2-a2da4be701f7@lab.ntt.co.jp

 · 

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-bugs@postgresql.org
  Cc: Langote_Amit_f8@lab.ntt.co.jp, sfrost@snowman.net, diptatapa@gmail.com, tgl@sss.pgh.pa.us
  Subject: Re: Scanning all partition when more than 100 items in "where id in ()" clause
  In-Reply-To: <99ac127f-d5b4-961f-08c2-a2da4be701f7@lab.ntt.co.jp>
  References: <20180727022353.GJ27724@tamriel.snowman.net> <5c46f111-81a8-3156-016e-2b70d6985b4d@lab.ntt.co.jp> <99ac127f-d5b4-961f-08c2-a2da4be701f7@lab.ntt.co.jp>

* 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