test=# create table demo(id serial, d date, val numeric) partition by range (d);
CREATE TABLE
test=*# create table demo_2016 partition of demo for values from ('2016-01-01') to ('2017-01-01');
CREATE TABLE
test=*# create table demo_2017 partition of demo for values from ('2017-01-01') to ('2018-01-01');
CREATE TABLE
test=*# create table demo_2018 partition of demo for values from ('2018-01-01') to ('2019-01-01');
CREATE TABLE
test=*# insert into demo (d, val) select '2016-01-01'::date + random() * 1000 * '1day'::interval, random() * 1000 from generate_series(1,10000000) s;
INSERT 0 10000000
test=*# analyse demo;
ANALYZE
test=*# explain analyse select * from demo where d = '2018-10-18'::date;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------
Gather (cost=1000.00..33158.03 rows=9965 width=19) (actual time=132.371..139.374 rows=0 loops=1)
Workers Planned: 2
Workers Launched: 2
-> Parallel Append (cost=0.00..31161.53 rows=4152 width=19) (actual time=127.399..127.399 rows=0 loops=3)
-> Parallel Seq Scan on demo_2018 (cost=0.00..31140.77 rows=4152 width=19) (actual time=127.397..127.397 rows=0 loops=3)
Filter: (d = '2018-10-18'::date)
Rows Removed by Filter: 896561
Planning Time: 1.092 ms
Execution Time: 139.406 ms
(9 rows)
test=*#