Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fiywQ-0007hb-PO for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Jul 2018 09:21:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fiywP-00083N-00 for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Jul 2018 09:21:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fiywO-00083F-Pg for pgsql-bugs@lists.postgresql.org; Fri, 27 Jul 2018 09:21:40 +0000 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fiywF-0004AC-DW for pgsql-bugs@postgresql.org; Fri, 27 Jul 2018 09:21:37 +0000 Received: from vc2.ecl.ntt.co.jp (vc2.ecl.ntt.co.jp [129.60.86.154]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id w6R9LPgG030227; Fri, 27 Jul 2018 18:21:25 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 8C9586390F3; Fri, 27 Jul 2018 18:21:25 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 8150E639066; Fri, 27 Jul 2018 18:21:25 +0900 (JST) Received: from [127.0.0.1] (unknown [129.60.241.61]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 7B35E400AD4; Fri, 27 Jul 2018 18:21:25 +0900 (JST) Subject: Re: Scanning all partition when more than 100 items in "where id in ()" clause From: Amit Langote References: <20180727022353.GJ27724@tamriel.snowman.net> <5c46f111-81a8-3156-016e-2b70d6985b4d@lab.ntt.co.jp> Message-ID: <99ac127f-d5b4-961f-08c2-a2da4be701f7@lab.ntt.co.jp> Date: Fri, 27 Jul 2018 18:21:13 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <5c46f111-81a8-3156-016e-2b70d6985b4d@lab.ntt.co.jp> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-CC-Mail-RelayStamp: 1 To: Stephen Frost , Soni M , Tom Lane Cc: Postgres Bug X-TM-AS-MML: disable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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