Repository navigation
Closed
Closed
Copy link
Labels
ai-lightAI出初稿,人调一调kind/bugSomething isn't workingseverity/s1High impact: Logical errors or data errors that must occur
Milestone
Description
Summary
On latest main (0e8602b78), MySQL index hints are accepted but can produce incorrect results with composite secondary indexes:
USE INDEX(...)/FORCE INDEX FOR ORDER BY(...)/IGNORE INDEX FOR ORDER BY(...)return empty results for queries that return rows in MySQL.FORCE INDEX(idx_missing)does not report the missing index. MySQL returnsERROR 1176, while MO returns0.
Duplicate check
Searched before filing:
FORCE INDEXUSE INDEXIGNORE INDEXforce index missing indexUSE INDEX returns zero rows
No direct duplicate was found. Existing composite-index issues such as #25344/#25345/#25348/#25349/#25351 cover predicate/type/aggregate paths, not MySQL index-hint semantics.
Reproduce
drop database if exists mysql_compat_horizontal_index_hint;
create database mysql_compat_horizontal_index_hint;
use mysql_compat_horizontal_index_hint;
create table t (
id int primary key,
a varchar(8) not null,
b int not null,
c int not null,
status varchar(12),
score int,
dt datetime,
key idx_a_b_c_id(a,b,c,id),
key idx_b_a_id(b,a,id),
key idx_status_dt(status,dt,id)
);
insert into t values
(2,'g02',2,14,'archived',22,'2024-03-03 02:00:00'),
(42,'g02',5,29,'archived',58,'2024-07-15 18:00:00'),
(81,'g01',7,37,'pending',83,'2024-10-26 09:00:00'),
(82,'g02',8,44,'archived',94,'2024-11-27 10:00:00'),
(112,'g02',1,42,'active',20,'2024-05-01 16:00:00'),
(152,'g02',4,4,'active',56,'2024-09-13 08:00:00'),
(155,'g05',7,25,'hold',89,'2024-12-16 11:00:00'),
(192,'g02',7,19,'active',92,'2024-01-25 00:00:00'),
(222,'g02',0,17,'archived',14,'2024-07-27 06:00:00'),
(232,'g02',10,34,'active',23,'2024-05-09 16:00:00');
select id,a,b,c
from t use index(idx_b_a_id)
where b=7 and a in ('g01','g03','g05')
order by a,id;
select id,a,b,c
from t force index for order by(idx_a_b_c_id)
where a in ('g02','g04')
order by a,b,c,id
limit 8;
select count(*)
from t force index(idx_missing)
where a='g01';Expected result
Matches MySQL 8.0.45:
-- USE INDEX
81 g01 7 37
155 g05 7 25
-- FORCE INDEX FOR ORDER BY
222 g02 0 17
112 g02 1 42
2 g02 2 14
152 g02 4 4
42 g02 5 29
192 g02 7 19
82 g02 8 44
232 g02 10 34
-- missing index
ERROR 1176 (42000): Key 'idx_missing' doesn't exist in table 't'
Actual result on MO
-- USE INDEX
empty result
-- FORCE INDEX FOR ORDER BY
empty result
-- missing index
0
Metadata
Metadata
Assignees
Labels
ai-lightAI出初稿,人调一调kind/bugSomething isn't workingseverity/s1High impact: Logical errors or data errors that must occur
Activity
Ariznawlll commentedon Jul 2, 2026
Supplemental index-hint coverage on latest main
51656deb6:On a composite-PK table with composite secondary indexes, hinting changes correct counts into zero. In one repro, the unhinted count happened to match MySQL, but both
FORCE INDEXandIGNORE INDEXreturned zero:This confirms the hint issue is not limited to a simple integer-primary-key table; it also reproduces with owner-bound composite primary keys and secondary indexes that append the PK columns.
fix(plan): honor mysql index hints (#25573)
Ariznawlll commentedon Jul 13, 2026
已在最新
main上完成验证,并补充 motr 回归测试。验证环境
main@52afd25fa63a3cb6037b7bf8ff0bf1328c4793ecissue_25356_index_hints测试过程
使用 issue 中的复合索引表结构和数据,覆盖:
USE INDEX(idx_b_a_id)+ 等值/IN 条件,检查实际返回行。FORCE INDEX FOR ORDER BY(idx_a_b_c_id)+ 排序和 LIMIT。IGNORE INDEX FOR ORDER BY(idx_a_b_c_id)+LIMIT/OFFSET。FORCE INDEX下执行 GROUP BY、COUNT 和 SUM。idx_missing,要求返回 MySQL 错误 1176。验证结果
ERROR 1176: Key 'idx_missing' doesn't exist in table 't'。fix(plan): honor mysql index hints (matrixorigin#25573)
fix(plan): honor mysql index hints (matrixorigin#25573)
fix(plan): honor mysql index hints (matrixorigin#25573)