Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql 规则 JOIN字段必须包含索引 优化 #2568

Open
taolx0 opened this issue Aug 29, 2024 · 0 comments
Open

mysql 规则 JOIN字段必须包含索引 优化 #2568

taolx0 opened this issue Aug 29, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@taolx0
Copy link
Collaborator

taolx0 commented Aug 29, 2024

版本信息(Version)

main

问题描述(Describe)

两张表关联join,假设驱动表的连接字段是非索引字段,该条规则会误触发.无论驱动表连接字段有没有索引,驱动表走的都是全表扫描,所以规则只需要判断被驱动表连接字段是否是索引字段即可,不需要判断驱动表连接字段是不是索引字段.

截图或日志(Log)

如何复现(To Reproduce)

  1. 存在以下两张表
CREATE TABLE t1
(
    c1 int,
    c2 int,
    INDEX (c1)
);

CREATE TABLE t2
(
    c1 int,
    INDEX (c1)
);
  1. 开启规则 JOIN字段必须包含索引,审核以下SQL
SELECT *
FROM t1
         LEFT JOIN t2 ON t1.c2 = t2.c1;
  1. 审核结果触发 JOIN字段必须包含索引 规则,复现成功

问题原因

规则对驱动表连接字段检测是否是索引字段导致的

解决方案

参考:
left/right join 不判断驱动表连接字段是否是索引字段,innner join 根据执行计划结果得出哪张表驱动表

变更影响面

受影响的模块或功能

外部引用的潜在问题或风险

版本兼容性

测试建议

@taolx0 taolx0 added the bug Something isn't working label Aug 29, 2024
@sjjian sjjian added this to the v3.2409.0 milestone Aug 29, 2024
@ColdWaterLW ColdWaterLW modified the milestones: v3.2409.0, v3.2410.0 Oct 8, 2024
@ColdWaterLW ColdWaterLW removed this from the v3.2410.0 milestone Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants