pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #14173: Not using partitions with ANY(ARRAY[...])
2+ messages / 2 participants
[nested] [flat]
* BUG #14173: Not using partitions with ANY(ARRAY[...])
@ 2016-06-03 10:37 furstenheim@gmail.com
2016-06-03 14:22 ` Re: BUG #14173: Not using partitions with ANY(ARRAY[...]) Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: furstenheim@gmail.com @ 2016-06-03 10:37 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 14173
Logged by: Gabriel f
Email address: furstenheim@gmail.com
PostgreSQL version: 9.5.2
Operating system: Ubuntu 64bit
Description:
http://stackoverflow.com/questions/34766671/how-to-query-against-several-tables-from-a-partition-in-...
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.
I've seen the error both in 9.4 and in 9.5.2. However, according to some
comment in the provided link it did work properly with 9.3
Thanks
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #14173: Not using partitions with ANY(ARRAY[...])
2016-06-03 10:37 BUG #14173: Not using partitions with ANY(ARRAY[...]) furstenheim@gmail.com
@ 2016-06-03 14:22 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2016-06-03 14:22 UTC (permalink / raw)
To: furstenheim@gmail.com; +Cc: pgsql-bugs
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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2016-06-03 14:22 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-06-03 10:37 BUG #14173: Not using partitions with ANY(ARRAY[...]) furstenheim@gmail.com
2016-06-03 14:22 ` Tom Lane <tgl@sss.pgh.pa.us>
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