Skip to content

[Bug] When querying, if the value of the time partition field is the result of the str_to_date function, it is found that the partitions cannot be filtered correctly, resulting in a full table scan during the query #50305

@guoyucui

Description

@guoyucui

Search before asking

  • I had searched in the issues and found no similar issues.

Version

2.0.1

What's Wrong?

Image

Image

用来验证的表和对应的sql:
drop table if exists py_test.test_sql;
CREATE TABLE if not exists py_test.test_sql
(
date date not null comment '订单日期',
order_id varchar(64) not null comment '订单ID',
project_name varchar(64) not null comment '项目名'
) ENGINE = OLAP
UNIQUE KEY(date,order_id)
comment '测试索引的表'
PARTITION BY RANGE(date)()
DISTRIBUTED BY HASH(date) BUCKETS 1
PROPERTIES (
"enable_unique_key_merge_on_write" = "true",
"dynamic_partition.enable" = "true",
"dynamic_partition.time_unit" = "MONTH",
"dynamic_partition.time_zone" = "UTC",
"dynamic_partition.end" = "2",
"dynamic_partition.prefix" = "p",
"dynamic_partition.buckets" = "1",
"dynamic_partition.create_history_partition" = "true",
"dynamic_partition.history_partition_num" = "6",
"dynamic_partition.hot_partition_num" = "0",
"replication_num" = "1"
);

初始化数据:insert into py_test.test_sql
values
('2025-04-22','123456','xxx测试项目'),
('2025-04-01','123457','xxx测试项目'),
('2025-03-22','123458','xxx测试项目'),
('2025-03-01','123459','xxx测试项目'),
('2025-02-22','1234510','xxx测试项目'),
('2025-02-01','1234511','xxx测试项目'),
('2025-01-22','1234512','xxx测试项目'),
('2025-01-01','1234513','xxx测试项目');

insert into py_test.test_sql
values
('2024-12-22','1234514','xxx测试项目'),
('2024-12-01','1234515','xxx测试项目'),
('2024-11-22','1234516','xxx测试项目'),
('2024-11-01','1234517','xxx测试项目');

验证sql:
explain
select * from py_test.test_sql
where date>=str_to_date('2025-03-01','%Y-%m-%d');
explain
select * from py_test.test_sql
where date>='2025-03-01 10:00:00';

What You Expected?

期望 当explain
select * from py_test.test_sql
where date>=str_to_date('2025-03-01','%Y-%m-%d'); 时 和 explain
select * from py_test.test_sql
where date>='2025-03-01 10:00:00'; 查询的分区数一致

How to Reproduce?

No response

Anything Else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions