Repository navigation
Closed
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
Other Environment Information
- MO version: 8.0.30-MatrixOne-v
- MySQL version: 8.0.45
- Verify date: 2026-07-02Actual Behavior
Covering queries over composite secondary indexes can return empty results, while the same predicate/order returns rows when the query needs to fetch a non-indexed column or when the table has no secondary index.
This affects ORDER BY ... LIMIT and DISTINCT style queries.
Expected Behavior
The covering index path, non-covering path, and no-secondary-index control table should return the same rows as MySQL.
Steps to Reproduce
drop database if exists mysql_compat_index_model_c;
create database mysql_compat_index_model_c;
use mysql_compat_index_model_c;
create table t_idx (
id int primary key,
tenant varchar(8) not null,
status varchar(12) null,
due date null,
amount decimal(10,2) null,
score int null,
payload varchar(30),
key idx_status_due_amount_id(status, due, amount, id),
key idx_tenant_score_id(tenant, score, id),
key idx_due_status_id(due, status, id)
);
create table t_scan (
id int primary key,
tenant varchar(8) not null,
status varchar(12) null,
due date null,
amount decimal(10,2) null,
score int null,
payload varchar(30)
);
insert into t_idx values
(1,'t1','active','2024-01-02',20.00,20,'p1'),
(2,'t1','active','2024-01-01',10.00,10,'p2'),
(3,'t1','active','2024-01-02',15.00,30,'p3'),
(4,'t2','paused','2024-01-03',30.00,40,'p4'),
(5,'t2','active',null,40.00,50,'p5'),
(6,'t3',null,'2024-01-04',50.00,60,'p6'),
(7,'t3','archived','2024-01-05',60.00,null,'p7'),
(8,'t4','active','2024-01-02',15.00,30,'p8'),
(9,'t4','active','2024-01-06',70.00,70,'p9'),
(10,'t5','paused','2024-01-01',5.00,5,'p10');
insert into t_scan select * from t_idx;
-- Covering query: only indexed columns
select id,status,due,amount
from t_idx
where status='active'
order by status,due,amount,id
limit 5;
-- Non-covering query: includes payload
select id,status,due,amount,payload
from t_idx
where status='active'
order by status,due,amount,id
limit 5;
-- No-secondary-index control
select id,status,due,amount
from t_scan
where status='active'
order by status,due,amount,id
limit 5;
-- DISTINCT over composite secondary index
select distinct tenant,score
from t_idx
where tenant >= 't1'
order by tenant,score;MySQL 8.0.45:
-- covering query and no-index control both return:
5 active NULL 40.00
2 active 2024-01-01 10.00
3 active 2024-01-02 15.00
8 active 2024-01-02 15.00
1 active 2024-01-02 20.00
-- DISTINCT returns tenant/score rows:
t1 10
t1 20
t1 30
t2 40
t2 50
t3 NULL
t3 60
t4 30
t4 70
t5 5
MatrixOne main 51656deb6:
-- covering query over t_idx:
empty result
-- non-covering query over t_idx:
5 active NULL 40.00 p5
2 active 2024-01-01 10.00 p2
3 active 2024-01-02 15.00 p3
8 active 2024-01-02 15.00 p8
1 active 2024-01-02 20.00 p1
-- no-secondary-index control:
same rows as MySQL
-- DISTINCT tenant,score over t_idx:
empty result
Additional information
This is separate from the existing index-only aggregate issues because the failing queries are row-returning covering SELECT / DISTINCT queries, not aggregate-only queries. It was found during the Index Model C ORDER BY / LIMIT / DISTINCT pass.
Activity
Ariznawlll commentedon Jul 2, 2026
Supplemental Index Model E type-mix coverage on latest main
51656deb6:The same covering-row-query issue also appears when the leading composite-secondary-index column is
DECIMAL.Table shape:
Observed:
Other type-mix paths in the same pass matched MySQL: binary leading equality/range, datetime leading equality/range, NULL predicates, and a non-leading decimal predicate under a binary leading key. This points again at specific covering composite-secondary-index row retrieval, not all type combinations.
Ariznawlll commentedon Jul 2, 2026
Supplemental Index Model I random-DML-chain coverage on latest main
51656deb6:After a deterministic 30-step DML chain, a covering row-returning query over a composite secondary index returned empty results while the no-secondary-index control matched MySQL.
Example at checkpoint_20:
The final full-row checksum matched between indexed/control tables, so this again points to covering secondary-index read retrieval rather than DML maintenance corruption.
ck89119 commentedon Jul 3, 2026
Root cause analysis
Same root cause as #25341 / #25348, not specific to the ORDER BY / DISTINCT paths themselves.
Every secondary index in the reproduction explicitly contains the primary key column (e.g.
idx_status_due_amount_id(status, due, amount, id)covers PKid). Before PR #25342,getValidIndexesinpkg/sql/plan/bind_insert.gosilently dropped such covering indexes from the DML maintenance list, so their hidden index tables stayed permanently empty, while the optimizer still chose them for the Index Table Scan. Any covering query served from the hidden index table — including the row-returningORDER BY ... LIMITandDISTINCTshapes here — therefore returned empty results, while the non-covering query (fetchingpayloadfrom the base table) and the no-index control table were unaffected.This issue was reported at commit
51656deb6, which is the direct parent of the fix commit2bf76218f.Fixed by #25342
Verified on latest
main(2a8f3b884, includes2bf76218f) with the full reproduction script from this issue, on a clean instance:All four queries (covering, non-covering, no-index control, DISTINCT) now match MySQL 8.0.45.
EXPLAINconfirms both previously-failing queries still go through the covering-index path (Index Table Scan on t_idx.idx_status_due_amount_id/idx_tenant_score_idwithserial_extractsort keys / group keys), i.e. the covering path itself is correct once the hidden index tables are maintained.Ariznawlll commentedon Jul 3, 2026
Verified on latest main @ 2a8f3b8. Covering ORDER BY/LIMIT, non-covering control, no-index control, and DISTINCT now all match MySQL 8.0.45. Fixed by #25342; closing.
Ariznawlll commentedon Jul 3, 2026
Regression case added in matrixorigin/motr#39.
Case:
14_issue_regression.issue_25396_composite_index_order_distinctCommit:
0bf1ab1Target branch marker:
@target-branch: mainValidation on latest main passed with the composite-index regression group: