建表语句
CREATE TABLE `test1` (
`datatime` datetime NOT NULL COMMENT '数据时间',
`id` varchar(255) NOT NULL COMMENT 'id',
`name` varchar(255) REPLACE NULL COMMENT '名称',
`storage_time` datetime REPLACE NULL DEFAULT CURRENT_TIMESTAMP COMMENT '插入时间'
) ENGINE=OLAP
AGGREGATE KEY(`datatime`,`id`)
COMMENT ''
PARTITION BY RANGE(`datatime`)
(PARTITION p20240729 VALUES [('2024-07-29 00:00:00'), ('2024-07-30 00:00:00')),
PARTITION p20241020 VALUES [('2024-10-20 00:00:00'), ('2024-10-21 00:00:00')),
PARTITION p20241117 VALUES [('2024-11-17 00:00:00'), ('2024-11-18 00:00:00')))
DISTRIBUTED BY HASH(`id`) BUCKETS AUTO
PROPERTIES (
"replication_allocation" = "tag.location.default: 3",
"min_load_replica_num" = "-1",
"is_being_synced" = "false",
"storage_format" = "V2",
"inverted_index_storage_format" = "DEFAULT",
"light_schema_change" = "true",
"disable_auto_compaction" = "false",
"enable_single_replica_compaction" = "false",
"group_commit_interval_ms" = "10000",
"group_commit_data_bytes" = "134217728"
);
测试数据
insert into test1 values('2024-07-29 12:10:00','1', 't1', '2024-10-11 12:10:00'),
('2024-10-20 12:10:00','2', 't2', '2024-10-11 12:10:00'),('2024-11-17 12:10:00','3', 't3', '2024-10-11 12:10:00');
问题SQL
explain select * from test1 where datatime = (select max(datatime) from test1 where datatime >= '2024-11-10 00:00:00')
预期是从最新的一个分区中查询数据,但实际scan的是全表三个分区partitions=3/3 (p20240729,p20241020,p20241117) (请忽略图中的分区名称)