Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b8q0i-0007Y7-CZ for pgsql-bugs@arkaria.postgresql.org; Fri, 03 Jun 2016 14:23:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1b8q0h-0006Gw-VD for pgsql-bugs@arkaria.postgresql.org; Fri, 03 Jun 2016 14:23: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.84_2) (envelope-from ) id 1b8q04-0005ZM-P2 for pgsql-bugs@postgresql.org; Fri, 03 Jun 2016 14:23:00 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b8q01-0006m4-Qw for pgsql-bugs@postgresql.org; Fri, 03 Jun 2016 14:23:00 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u53EMttE012956; Fri, 3 Jun 2016 10:22:55 -0400 From: Tom Lane To: furstenheim@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14173: Not using partitions with ANY(ARRAY[...]) In-reply-to: <20160603103744.30386.59358@wrigleys.postgresql.org> References: <20160603103744.30386.59358@wrigleys.postgresql.org> Comments: In-reply-to furstenheim@gmail.com message dated "Fri, 03 Jun 2016 10:37:44 -0000" Date: Fri, 03 Jun 2016 10:22:55 -0400 Message-ID: <12955.1464963775@sss.pgh.pa.us> X-Pg-Spam-Score: -3.3 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org furstenheim@gmail.com writes: > I'm querying a table partitioned wrt to some variable, say mvar. If I do: > explain select * from mtable where mvar = 'a' or mvar = 'b' > then the query planner goes only into the two subtables related to 'a' and > 'b'. > The same works with the static in > select * from mtable where mvar IN ('a', 'b') > However, it does not work if I use array > select * from mtable where mvar = ANY(ARRAY['a','b']) > the query planner schedules all subtables of the partition. Works for me: regression=# create table mtable (mvar int); CREATE TABLE regression=# create table c1 (check (mvar > 0 and mvar <= 10)) inherits(mtable); CREATE TABLE regression=# create table c2 (check (mvar > 10 and mvar <= 20)) inherits(mtable); CREATE TABLE regression=# explain select * from mtable where mvar = 3 or mvar = 4; QUERY PLAN ------------------------------------------------------------ Append (cost=0.00..48.25 rows=26 width=4) -> Seq Scan on mtable (cost=0.00..0.00 rows=1 width=4) Filter: ((mvar = 3) OR (mvar = 4)) -> Seq Scan on c1 (cost=0.00..48.25 rows=25 width=4) Filter: ((mvar = 3) OR (mvar = 4)) (5 rows) regression=# explain select * from mtable where mvar in (3, 4); QUERY PLAN ------------------------------------------------------------ Append (cost=0.00..41.88 rows=27 width=4) -> Seq Scan on mtable (cost=0.00..0.00 rows=1 width=4) Filter: (mvar = ANY ('{3,4}'::integer[])) -> Seq Scan on c1 (cost=0.00..41.88 rows=26 width=4) Filter: (mvar = ANY ('{3,4}'::integer[])) (5 rows) regression=# explain select * from mtable where mvar = any (array[3,4]); QUERY PLAN ------------------------------------------------------------ Append (cost=0.00..41.88 rows=27 width=4) -> Seq Scan on mtable (cost=0.00..0.00 rows=1 width=4) Filter: (mvar = ANY ('{3,4}'::integer[])) -> Seq Scan on c1 (cost=0.00..41.88 rows=26 width=4) Filter: (mvar = ANY ('{3,4}'::integer[])) (5 rows) regression=# explain select * from mtable where mvar = any (array[13,14]); QUERY PLAN ------------------------------------------------------------ Append (cost=0.00..41.88 rows=27 width=4) -> Seq Scan on mtable (cost=0.00..0.00 rows=1 width=4) Filter: (mvar = ANY ('{13,14}'::integer[])) -> Seq Scan on c2 (cost=0.00..41.88 rows=26 width=4) Filter: (mvar = ANY ('{13,14}'::integer[])) (5 rows) I speculate that you've got some sort of datatype mismatch problem, but without seeing an exact example it's hard to diagnose. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs