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规则,联合索引,必须使用联合索引的首字段误报错 #2721

Open
taolx0 opened this issue Oct 28, 2024 · 0 comments
Open

MySQL规则,联合索引,必须使用联合索引的首字段误报错 #2721

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

Comments

@taolx0
Copy link
Contributor

taolx0 commented Oct 28, 2024

版本信息(Version)

3.2409.0

问题描述(Describe)

MySQL规则,联合索引,必须使用联合索引的首字段误报错

截图或日志(Log)

image

如何复现(To Reproduce)

  1. 存在如下DDL
CREATE TABLE `user_1`
(
    `id`   int          NOT NULL AUTO_INCREMENT,
    `name` INT          NOT NULL,
    `age`  varchar(20)  NOT NULL,
    `desc` varchar(100) NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `IDX_UID_CHANNEL` (`name`, `age`),
    KEY `idx_PARTNER_UID_CHANNEL` (`desc`, `age`)
) ENGINE = InnoDB
  AUTO_INCREMENT = 2
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci;
  1. 审核该条SQL
SELECT *
FROM user_1
WHERE name = 't'
  AND age = 12;
  1. 复现

问题原因

表user_1存在两个联合索引,两个联合索引第二个字段都是 age 字段,联合索引最左不同,复现的SQL能满足IDX_UID_CHANNEL索引,但是不满足idx_PARTNER_UID_CHANNEL联合索引

UNIQUE KEY `IDX_UID_CHANNEL` (`name`, `age`),
KEY `idx_PARTNER_UID_CHANNEL` (`desc`, `age`)

解决方案

变更影响面

受影响的模块或功能

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

版本兼容性

测试建议

@taolx0 taolx0 added the bug Something isn't working label Oct 28, 2024
@taolx0 taolx0 changed the title 规则使用联合索引,必须使用联合索引的首字段误报 MySQL规则,联合索引,必须使用联合索引的首字段误报错 Oct 30, 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

2 participants