【 使用环境 】生产环境
【 OB or 其他组件 】
【 使用版本 】
【问题描述】分区表下有 id 全局查询,
【复现路径】
1 id、和 create_time 作为联合主键,以create_time 进行分区
partition by range columns(create_time)
(partition p_history values less than (‘2026-04-01 00:00:00’),
2 create_time 在左侧
PRIMARY KEY (create_time, id),
3 当前有 where id查询,explain 走了 全表扫描了。
SELECT
COUNT(*) AS total
FROM
book_record_info
WHERE
(id = ?)
============================================================================
|ID|OPERATOR |NAME |EST.ROWS|EST.TIME(us)|
----------------------------------------------------------------------------
|0 |SCALAR GROUP BY | |1 |13445326 |
|1 |└─PX COORDINATOR | |1 |13445326 |
|2 | └─EXCHANGE OUT DISTR |:EX10000 |1 |13445326 |
|3 | └─MERGE GROUP BY | |1 |13445325 |
|4 | └─PX PARTITION ITERATOR| |2 |13445325 |
|5 | └─TABLE FULL SCAN |book_recor_info|2 |13445325 |
============================================================================
Outputs & filters:
-------------------------------------
0 - output([T_FUN_COUNT_SUM(T_FUN_COUNT_SUM(T_FUN_COUNT(*)))]), filter(nil), rowset=16
group(nil), agg_func([T_FUN_COUNT_SUM(T_FUN_COUNT_SUM(T_FUN_COUNT(*)))])
1 - output([T_FUN_COUNT_SUM(T_FUN_COUNT(*))]), filter(nil), rowset=16
2 - output([T_FUN_COUNT_SUM(T_FUN_COUNT(*))]), filter(nil), rowset=16
dop=1
3 - output([T_FUN_COUNT_SUM(T_FUN_COUNT(*))]), filter(nil), rowset=16
group(nil), agg_func([T_FUN_COUNT_SUM(T_FUN_COUNT(*))])
4 - output([T_FUN_COUNT(*)]), filter(nil), rowset=16
force partition granule
5 - output([T_FUN_COUNT(*)]), filter([book_recor_info.id = demote_cast('2080501958866344416', BIGINT(20, 0))]), rowset=16
access([book_recor_info.id]), partitions(p[0-16])
is_index_back=false, is_global_index=false, filter_before_indexback[false],
range_key([book_recor_info.create_time], [book_recor_info.id]), range(MIN,MIN ; MAX,MAX)always true,
pushdown_aggregation([T_FUN_COUNT(*)])
问题:
如何优化,
1 创建 local还是 glable 的 id索引 ?
2 还是业务上避免 id 查询?
@论坛小助手