gpt4 book ai didi

database - greenplum分区优化

转载 作者:搜寻专家 更新时间:2023-10-30 23:19:23 25 4
gpt4 key购买 nike

在 greenplum 上,我有一个名为 fact_table 的大表,它按 RANGE(day_bucket) 分区。为什么以下查询这么慢:

select max(day_bucket) from fact_table where day_bucket >= '2011-09-11 00:00:00' and day_bucket < '2011-12-14'.

我想它应该只查看每个分区的头部并立即返回结果,因为相同的 day_bucket 列的每个分区。但是greenplum做了一次FULL扫描来计算结果。谁能给我解释一下原因?


更新:

感谢您回答我的问题,但这对您的提示没有帮助。 Greenplum 总是进行全面扫描,即使我使用 PARTITION BY LIST(day_bucket) 创建表也是如此:

CREATE TABLE fact_table (    id character varying(25) NOT NULL,    day_bucket timestamp without time zone NOT NULL,)WITH (appendonly=true, orientation=column, compresstype=zlib, compresslevel=6) DISTRIBUTED BY (user_id) PARTITION BY LIST(day_bucket)           (          PARTITION p20120101 VALUES ('2012-01-01 00:00:00'::timestamp without time zone) WITH (tablename='fact_table_1_prt_p20120101', appendonly=true, orientation=column, compresstype=zlib, compresslevel=6 ),           PARTITION p20120102 VALUES ('2012-01-02 00:00:00'::timestamp without time zone) WITH (tablename='fact_table_1_prt_p20120102', appendonly=true, orientation=column, compresstype=zlib, compresslevel=6 ),           PARTITION p20120103 VALUES ('2012-01-03 00:00:00'::timestamp without time zone) WITH (tablename='fact_table_1_prt_p20120103', appendonly=true, orientation=column, compresstype=zlib, compresslevel=6 ),           PARTITION p20120104 VALUES ('2012-01-04 00:00:00'::timestamp without time zone) WITH (tablename='fact_table_1_prt_p20120104', appendonly=true, orientation=column, compresstype=zlib, compresslevel=6 ),        .....

Explain 命令表明它总是进行全面扫描:

-> myteSTList_1_prt_p20120102 myteSTList 上的仅附加列扫描(成本=0.00..34.95 行=1 宽度=8) 过滤器:day_bucket >= '2012-01-02 00:00:00'::timestamp without time zone AND day_bucket Append-only Columnar Scan on myteSTList_1_prt_p20120103 myteSTList (cost=0.00..39.61 rows=1 width=8) 过滤器:day_bucket >= '2012-01-02 00:00:00'::timestamp without time zone AND day_bucket

最佳答案

您应该注意应用于分区的约束。为了让优化器正确地从扫描中排除一些分区,你应该帮助他。在您的情况下,您应该使用显式类型转换:(GP 在规划阶段无法自动理解像 'yyyy-mm-dd' 这样的刺痛实际上是时间戳)

select max(day_bucket) 
from fact_table
where day_bucket >= '2011-09-11 00:00:00'::timestamp
and day_bucket < '2011-12-14'::timestamp

关于database - greenplum分区优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8514154/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com