如何解决分区表的规划时间在 postgres 11 中花费了更多时间
我有不到 200 个分区(每日分区),每个分区有 5M+ 记录。
当我通过直接分区传递一天数据时,我看到估计计划为 0.01 毫秒,但在使用父表时为 190 毫秒(太多)。唯一观察到的区别是在计划中追加。
我们能否在 postgres 11 中消除 Append 或减少 修剪 时间?
查询:
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 ms
------------截取的表结构----
CREATE 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
解决方法
您可以升级到更高版本的 PostgreSQL,因为 v12 中的性能有所改进。
但是如果查询执行时间很短,计划时间总是占主导地位。您可以测试准备好的语句,但我怀疑运行时分区修剪会快得多。
从本质上讲,最差的查询性能是您为获得丢弃旧数据的简单方法而付出的预期代价。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。