CREATETABLE partitioned_table ( a int, b int, c int, p int ) PARTITION BY RANGE (p);
CREATETABLE p1 PARTITIONOF partitioned_table FORVALUESFROM (0) TO (10); CREATETABLE p2 PARTITIONOF partitioned_table FORVALUESFROM (10) TO (20);
INSERTINTO partitioned_table SELECT g.x, g.x, g.x, g.x FROM generate_series (0,19) AS g(x);
CREATEINDEXON partitioned_table(p);
CREATETABLE other_table ( p int, r int );
INSERTINTO other_table SELECT1, g.x FROM generate_series(1,100) AS g(x);
VACUUMANALYZE partitioned_table, other_table;
EXPLAIN (settings, analyze, costsoff, timingoff, summaryoff) SELECT a, b, c FROM partitioned_table WHERE p IN (SELECT p FROM other_table WHERE r between1and100);
QUERY PLAN ----------------------------------------------------------------------------------------- Nested Loop (actual rows=1 loops=1) -> HashAggregate (actual rows=1 loops=1) Group Key: other_table.p Batches: 1 Memory Usage: 24kB -> Seq Scan on other_table (actual rows=100 loops=1) Filter: ((r >= 1) AND (r <= 100)) -> Append (actual rows=1 loops=1) -> Index Scan using p1_p_idx on p1 partitioned_table_1 (actual rows=1 loops=1) Index Cond: (p = other_table.p) -> Index Scan using p2_p_idx on p2 partitioned_table_2 (never executed) Index Cond: (p = other_table.p) (11rows)