Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ehB9l-0004Xb-Qr for pgsql-bugs@arkaria.postgresql.org; Thu, 01 Feb 2018 09:27:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ehB9j-0002RL-M6 for pgsql-bugs@arkaria.postgresql.org; Thu, 01 Feb 2018 09:27:43 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ehB9j-0002R2-DK for pgsql-bugs@lists.postgresql.org; Thu, 01 Feb 2018 09:27:43 +0000 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ehB9d-0003ZS-OO; Thu, 01 Feb 2018 09:27:40 +0000 Received: from vc2.ecl.ntt.co.jp (vc2.ecl.ntt.co.jp [129.60.86.154]) by tama500.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id w119RXZp012014; Thu, 1 Feb 2018 18:27:33 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id CC0175F612; Thu, 1 Feb 2018 18:27:33 +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 C0B385F593; Thu, 1 Feb 2018 18:27:33 +0900 (JST) Received: from [127.0.0.1] (unknown [129.60.241.61]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id BBF1C400B9F; Thu, 1 Feb 2018 18:27:33 +0900 (JST) Subject: Re: BUG #15042: Parition by list using enums odd behaviour References: <151747550943.1247.2111555422760537959@wrigleys.postgresql.org> From: Amit Langote Message-ID: <2b20c220-50cb-3fae-da57-92e8cb3675dd@lab.ntt.co.jp> Date: Thu, 1 Feb 2018 18:27:23 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <151747550943.1247.2111555422760537959@wrigleys.postgresql.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-CC-Mail-RelayStamp: 1 To: damir.ciganovic.jankovic@gmail.com, pgsql-bugs@lists.postgresql.org, PG Bug reporting form X-TM-AS-MML: disable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2018/02/01 17:58, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 15042 > Logged by: Damir Ciganović-Janković > Email address: damir.ciganovic.jankovic@gmail.com > PostgreSQL version: 10.1 > Operating system: Windows 10 > Description: > > First time asking question, if you like stackoverflow, check this link > https://stackoverflow.com/questions/48502345/postgresql-10-partition-by-list-using-enums?noredirect=1#comment84079025_48502345 > > If not, I will explain. I am trying to partition my table using enum as > partition condition, this is what I did: > > create type positivity as enum ( > 'POSITIVE', > 'NEGATIVE' > ); > > create table test (id int, polarity positivity) partition by list > (polarity); > create table test_1 partition of test for values in ('POSITIVE'); > create table test_2 partition of test for values in ('NEGATIVE'); > > #### > > explain select * from test where polarity = 'NEGATIVE'; > (output:) > explain select * from test where polarity = 'NEGATIVE'; > QUERY PLAN > -------------------------------------------------------------- > Append (cost=0.00..76.50 rows=22 width=8) > -> Seq Scan on test_1 (cost=0.00..38.25 rows=11 width=8) > Filter: (polarity = 'NEGATIVE'::positivity) > -> Seq Scan on test_2 (cost=0.00..38.25 rows=11 width=8) > Filter: (polarity = 'NEGATIVE'::positivity) > (5 rows) > > > #### > I expected that it will only scan test_2, adding constraints on both > partitions will get me desired behaviour: > > alter table test_1 add constraint test_1_check check(polarity='POSITIVE'); > alter table test_2 add constraint test_2_check check(polarity='NEGATIVE'); > > explain select * from test where polarity = 'NEGATIVE'; > (output:) > QUERY PLAN > -------------------------------------------------------------- > Append (cost=0.00..38.25 rows=11 width=8) > -> Seq Scan on test_2 (cost=0.00..38.25 rows=11 width=8) > Filter: (polarity = 'NEGATIVE'::positivity) > (3 rows) > > ### > > Is this a bug or is it not implemented yet maybe? Or is it working as > intended? Yeah, it is a bug. Thanks for reporting it to this mailing list. I had posted a bug-fix patch in the context of similar thing happening when list partitioning using an array type column. See it here: https://www.postgresql.org/message-id/54745d13-7ed4-54ac-97d8-ea1eec95ae25%40lab.ntt.co.jp Looks like the underlying issue is same here, so the patch there will fix this bug too. If you'd like, please try the patch. I will try to revive the discussion on that patch, so that someone picks it up and maybe the bug will be fixed in the next minor version (10.2). Thanks, Amit [1] https://www.postgresql.org/message-id/54745d13-7ed4-54ac-97d8-ea1eec95ae25%40lab.ntt.co.jp