I have a big table partition in PostgreSQL by disjoint conditions.
Something like:
CREATE TABLE child_table_1(check(my_condition = '01')) INHERITS (parent_table);
// ...
CREATE TABLE child_table_20(check(my_condition = '20')) INHERITS (parent_table);
When I do a query like:
EXPLAIN SELECT * FROM parent_table WHERE my_condition = '12' or my_condition = '14';
then the query planner works as expected and shows:
Append (cost=0.00..21424.65 rows=100 width=60)
-> Seq Scan on parent_table (cost=0.00..0.00 rows=1 width=30)
Filter: ((my_condition = '12'::bpchar) OR (my_condition= '14'::bpchar))
-> Seq Scan on child_table_12 (cost=0.00..14790.10 rows=50 width=20)
Filter: ((my_condition = '12'::bpchar) OR (my_condition = '14'::bpchar))
-> Seq Scan on child_table_14 (cost=0.00..6634.55 rows=50 width=10)
Filter: ((my_condition = '12'::bpchar) OR (my_condition = '14'::bpchar))
However if I try a more dynamic approach,
EXPLAIN SELECT * FROM parent_table WHERE my_condition = ANY(array['12','04'])
it goes crazy and it tries to scan all the tables in the partition.
How should I modify the conditions for the child tables so it can be recognized?
Otherwise, how could I dynamically query against several child tables without writing a condition for each key.