为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
- 【TiDB 版本】:4.0.8
- 【问题描述】:
show index from tablename 里 Cardinality 一直为 0,怎么协助执行计划选择唯一性更高的索引
select xxx
from t1 left join t2 on t1.code = t2.code
where t1.xx_id = 1111
and t2.status = 2
and t2.type = 3
and t1.time >= '‘2020-11-05 13:00:00’
ann (t1.status = 3 or t1.status = 4)
从执行计划来看,t2.status、t2.type 把谓词推到里面先计算了,本 SQL 最好的方式应该是 t1 的结果集根据关联字段 code 进行匹配,t2.code 是 t2 表的唯一索引。
若提问为性能优化、故障排查类问题,请下载脚本运行。终端输出打印结果,请务必全选并复制粘贴上传。