我有不到200个分区(每日分区),每个分区都有5M+记录。
当我用直接分区传递一天数据时,我看到了估计的计划0.01ms,但是当使用父表190 but时(太多了)。只有观察到的差异才会附加在计划中。
我们能否消除附加或减少剪枝时间在postgres 11中?
查询:
explain (ANALYZE, VERBOSE, COSTS, BUFFERS, TIMING,SUMMARY) select 1 from test WHERE date1 >'2021-01-27 13:41:26' and date1<'2021-01-27 21:41:26' and own=123 and mob=123454234
----------------------------plan-----------
Append (cost=0.12..4.19 rows=1 width=4) (actual time=0.018..0.018 rows=0 loops=1)
Buffers: shared hit=1
-> Index Only Scan using test_20210127_pkey on test_20210127 (cost=0.12..4.17 rows=1 width=4) (actual time=0.017..0.017 rows=0 loops=1)
Output: 1
Index Cond: ((test_20210127.date1 > '2021-01-27 13:41:26'::timestamp without time zone) AND (test_20210127.date1 < '2021-01-27 21:41:26'::timestamp without time zone) AND (test_20210127.own = 123) AND (test_20210127.mob = 123454234))
Heap Fetches: 0
Buffers: shared hit=1
Planning Time: 190.440 ms
Execution Time: 0.093 msCREATE TABLE public.test
(
own integer NOT NULL,
mob bigint NOT NULL,
date1 timestamp without time zone NOT NULL,
ver integer NOT NULL,
c5
...
c100
CONSTRAINT test_pkey PRIMARY KEY (date1, own, mob, ver)
USING INDEX TABLESPACE tb_1
) PARTITION BY RANGE (date1)
WITH (
OIDS = FALSE
)
TABLESPACE tb_1;
-- Partitions SQL
CREATE TABLE public.test_20211003 PARTITION OF public.test
FOR VALUES FROM ('2020-10-03 00:00:00') TO ('2020-10-04 00:00:00');
CREATE TABLE public.test_201004 PARTITION OF public.test
FOR VALUES FROM ('2020-10-04 00:00:00') TO ('2020-10-05 00:00:00');
........6 months partitions发布于 2021-04-14 05:43:51
您可以升级到更高的PostgreSQL版本,因为v12中有性能改进。
但是,如果查询执行时间短,则计划时间将始终占主导地位。您可以测试一条准备好的语句,但我怀疑运行时分区修剪是否会更快。
本质上,更糟糕的查询性能是您为了简单的丢弃旧数据的方法而付出的预期代价。
https://stackoverflow.com/questions/67085988
复制相似问题