TiDB should support equivalence class propagation for JOIN op #39217
Labels
affects-6.5
may-affects-4.0
This bug maybe affects 4.0.x versions.
may-affects-5.0
This bug maybe affects 5.0.x versions.
may-affects-5.1
This bug maybe affects 5.1.x versions.
may-affects-5.2
This bug maybe affects 5.2.x versions.
may-affects-5.3
This bug maybe affects 5.3.x versions.
may-affects-5.4
This bug maybe affects 5.4.x versions.
may-affects-6.0
may-affects-6.1
may-affects-6.2
may-affects-6.3
may-affects-6.4
sig/planner
SIG: Planner
type/enhancement
The issue or PR belongs to an enhancement.
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
有四个表:
两个sql语句,差别只有黑体部分,输出结果差异是 p3 是否做了 FullIndexScan
sql1 :=
desc
SELECT
/*+TIDB_HJ(p0,p1,p3),TIDB_INLJ(p2)*/
p0.tenant_id,
p0.poi_id,
p0.spu_id,
p0.name AS spu_name
FROM
p0
JOIN p1 ON p0.tenant_id = p1.tenant_id
AND p0.poi_id = p1.poi_id
AND p0.spu_id = p1.spu_id
JOIN p2 ON p1.tenant_poi_id = p2.tenant_poi_id
AND p1.spu_id = p2.spu_id
LEFT JOIN p3 ON p1.tenant_id = p3.tenant_id
AND p1.poi_id = p3.poi_id
AND p2.category_id = p3.category_id
WHERE
p0.tenant_id IN ('10312060')
AND p0.poi_id IN ('600491386')
AND p0.spu_id IN ('2840204741')`
sql2 := "desc
SELECT
/*+TIDB_HJ(p0,p1,p3),TIDB_INLJ(p2)*/
p0.tenant_id,
p0.poi_id,
p0.spu_id,
p0.name AS spu_name
FROM
p0
JOIN p1 ON p0.tenant_id = p1.tenant_id
AND p0.poi_id = p1.poi_id
AND p0.spu_id = p1.spu_id
JOIN p2 ON p1.tenant_poi_id = p2.tenant_poi_id
AND p1.spu_id = p2.spu_id
LEFT JOIN p3 ON p0.tenant_id = p3.tenant_id
AND p0.poi_id = p3.poi_id
AND p2.category_id = p3.category_id
WHERE
p0.tenant_id IN ('10312060')
AND p0.poi_id IN ('600491386')
AND p0.spu_id IN ('2840204741');"
Join 形式是:((p0 inner join p1) inner join p2) left outer join p3
sql1中,p1的等值查询常量,没有传递给 p3,造成了 FullIndexScan
问题的原因是:逻辑优化阶段递归执行,给p3做常量传播优化时,((p0 inner join p1) inner join p2) 还没有做优化,还没有p2的等值谓词,所以关于p0的等值谓词,无法传递给p3。
2. What did you expect to see? (Required)
sql1没有对p3做优化
3. What did you see instead (Required)
sql1 也能产生sql2的优化结果
4. What is your TiDB version? (Required)
所有版本
The text was updated successfully, but these errors were encountered: