\set num_rows 1000 drop table t1; drop table p cascade; create table t1 (a int, b varchar, c timestamp) partition by range(a); create table t1p1 (b varchar, c timestamp, a int) partition by range(a); alter table t1 attach partition t1p1 for values from (0) to (100); create table t1p1p1(c timestamp, a int, b varchar); alter table t1p1 attach partition t1p1p1 for values from (0) to (50); insert into t1 select abs(random()) * 49, i, now() from generate_series(1, :num_rows) i; explain analyze select t1 from t1; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Append (cost=0.00..21.30 rows=1130 width=32) (actual time=0.516..1.371 rows=1000 loops=1) -> Seq Scan on t1p1p1 (cost=0.00..21.30 rows=1130 width=32) (actual time=0.514..1.300 rows=1000 loops=1) Planning time: 0.567 ms Execution time: 1.432 ms (4 rows) explain analyze select t1 from t1; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Append (cost=0.00..21.30 rows=1130 width=32) (actual time=0.016..0.831 rows=1000 loops=1) -> Seq Scan on t1p1p1 (cost=0.00..21.30 rows=1130 width=32) (actual time=0.015..0.751 rows=1000 loops=1) Planning time: 0.081 ms Execution time: 0.881 ms (4 rows) explain analyze select t1 from t1; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Append (cost=0.00..21.30 rows=1130 width=32) (actual time=0.013..0.816 rows=1000 loops=1) -> Seq Scan on t1p1p1 (cost=0.00..21.30 rows=1130 width=32) (actual time=0.013..0.747 rows=1000 loops=1) Planning time: 0.068 ms Execution time: 0.863 ms (4 rows) explain analyze select t1 from t1; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Append (cost=0.00..21.30 rows=1130 width=32) (actual time=0.013..0.814 rows=1000 loops=1) -> Seq Scan on t1p1p1 (cost=0.00..21.30 rows=1130 width=32) (actual time=0.012..0.746 rows=1000 loops=1) Planning time: 0.066 ms Execution time: 0.861 ms (4 rows) create table p (a int, b varchar, c timestamp); create table p_c (b varchar, c timestamp, a int, d int); alter table p_c inherit p; create table p_c_c (c timestamp, a int, b varchar, d int, e int); alter table p_c_c inherit p_c; insert into p_c_c select c, a, b, a, a from t1; explain analyze select p from p; QUERY PLAN ------------------------------------------------------------------------------------------------------------- Append (cost=0.00..20.20 rows=1022 width=32) (actual time=0.039..0.891 rows=1000 loops=1) -> Seq Scan on p (cost=0.00..0.00 rows=1 width=68) (actual time=0.001..0.001 rows=0 loops=1) -> Seq Scan on p_c (cost=0.00..0.00 rows=1 width=32) (actual time=0.000..0.000 rows=0 loops=1) -> Seq Scan on p_c_c (cost=0.00..20.20 rows=1020 width=32) (actual time=0.036..0.804 rows=1000 loops=1) Planning time: 0.176 ms Execution time: 0.951 ms (6 rows) explain analyze select p from p; QUERY PLAN ------------------------------------------------------------------------------------------------------------- Append (cost=0.00..20.20 rows=1022 width=32) (actual time=0.030..0.728 rows=1000 loops=1) -> Seq Scan on p (cost=0.00..0.00 rows=1 width=68) (actual time=0.001..0.001 rows=0 loops=1) -> Seq Scan on p_c (cost=0.00..0.00 rows=1 width=32) (actual time=0.000..0.000 rows=0 loops=1) -> Seq Scan on p_c_c (cost=0.00..20.20 rows=1020 width=32) (actual time=0.028..0.659 rows=1000 loops=1) Planning time: 0.061 ms Execution time: 0.782 ms (6 rows) explain analyze select p from p; QUERY PLAN ------------------------------------------------------------------------------------------------------------- Append (cost=0.00..20.20 rows=1022 width=32) (actual time=0.012..0.710 rows=1000 loops=1) -> Seq Scan on p (cost=0.00..0.00 rows=1 width=68) (actual time=0.001..0.001 rows=0 loops=1) -> Seq Scan on p_c (cost=0.00..0.00 rows=1 width=32) (actual time=0.000..0.000 rows=0 loops=1) -> Seq Scan on p_c_c (cost=0.00..20.20 rows=1020 width=32) (actual time=0.010..0.640 rows=1000 loops=1) Planning time: 0.060 ms Execution time: 0.762 ms (6 rows) explain analyze select p from p; QUERY PLAN ------------------------------------------------------------------------------------------------------------- Append (cost=0.00..20.20 rows=1022 width=32) (actual time=0.013..0.774 rows=1000 loops=1) -> Seq Scan on p (cost=0.00..0.00 rows=1 width=68) (actual time=0.001..0.001 rows=0 loops=1) -> Seq Scan on p_c (cost=0.00..0.00 rows=1 width=32) (actual time=0.000..0.000 rows=0 loops=1) -> Seq Scan on p_c_c (cost=0.00..20.20 rows=1020 width=32) (actual time=0.011..0.691 rows=1000 loops=1) Planning time: 0.072 ms Execution time: 0.829 ms (6 rows)