Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l4pF9-00042C-W4 for pgsql-bugs@arkaria.postgresql.org; Wed, 27 Jan 2021 18:08:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l4pF8-00019x-EI for pgsql-bugs@arkaria.postgresql.org; Wed, 27 Jan 2021 18:08:38 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l4pF8-00019p-8S for pgsql-bugs@lists.postgresql.org; Wed, 27 Jan 2021 18:08:38 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l4pF6-000252-35 for pgsql-bugs@lists.postgresql.org; Wed, 27 Jan 2021 18:08:37 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 10RI8YJ22407556; Wed, 27 Jan 2021 13:08:34 -0500 From: Tom Lane To: michalalbrycht@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16840: Rows not found in table partitioned by hash when not all partitions exists In-reply-to: <16840-571a22976f829ad4@postgresql.org> References: <16840-571a22976f829ad4@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Wed, 27 Jan 2021 17:02:21 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2407554.1611770914.1@sss.pgh.pa.us> Date: Wed, 27 Jan 2021 13:08:34 -0500 Message-ID: <2407555.1611770914@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > CREATE TABLE dir ( > id SERIAL, > volume_id BIGINT, > path TEXT > ) PARTITION BY HASH (volume_id); > CREATE TABLE dir_part_2 PARTITION OF dir FOR VALUES WITH (modulus 3, > remainder 2); > SELECT * FROM dir WHERE volume_id=1 AND (path='abc' OR path='def') -- > returns 0 rows - NOT OK! Hmm, seems to be a case of faulty partition exclusion, because the plan isn't scanning anything: =# explain SELECT * FROM dir WHERE volume_id=1 AND (path='abc' OR path='def'); QUERY PLAN ------------------------------------------ Result (cost=0.00..0.00 rows=0 width=0) One-Time Filter: false (2 rows) Probably the reason we'd not noticed is that an incomplete set of hash partitions isn't a very useful situation: if you don't populate all of the partitions, you risk unexpected insertion failures, since you really shouldn't be assuming which partition any given key value will map into. Still, it's clearly a bug. Thanks for the report! regards, tom lane