简体   繁体   English

查询 PostgreSQL 上的分区表

[英]Query on partitioned table on PostgreSQL

I have a table partitioned by year.我有一个按年份分区的表。 With this query :有了这个查询:

select *
from myTable
where year between '2018' and '2020'

the query plan is good, only 2018,2019,2020 partitions are used.查询计划不错,只用了2018、2019、2020个分区。

But with this query但是有了这个查询

select *
from myTable
where year between '2018' and extract(year from now())::text

the partitions 2021 and 2022 appears in the query plan, why ?分区 2021 和 2022 出现在查询计划中,为什么?

In PostgreSQL v10, partition pruning (removal of unneeded partitions) can only happen at query planning time, but at that time the value of extract(year from now())::text is not known.在 PostgreSQL v10 中,分区修剪(删除不需要的分区)只能在查询计划时发生,但此时extract(year from now())::text是未知的。

If you use PostgreSQL v11 or later, your query should perform as expected.如果您使用 PostgreSQL v11 或更高版本,您的查询应该按预期执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM