Repository navigation
Description
Is there an existing issue for the same bug?
I have checked the existing issues.
I found closed issue #24304 mentioning prefix_between, but that issue describes a development-time seek optimization problem and says block filtering still validates rows, so it should not cause incorrect query results. The case below reproduces an incorrect result on latest main.
Branch Name
main
Commit ID
0e8602b78
Other Environment Information
- Local MatrixOne built from latest
origin/main - MySQL oracle: MySQL 8.0.45
Actual Behavior
For a table with an all-VARCHAR composite primary key and a composite secondary index whose leading column is VARCHAR, range predicates on that indexed VARCHAR column return zero rows through the secondary-index path.
The same data and predicate return the expected rows on:
- MySQL
- MatrixOne control table without the secondary index
Observed on MatrixOne latest main:
idx_between 0
no_idx_between 2
idx_range 0
no_idx_range 2
EXPLAIN shows the wrong-result query uses the secondary index table scan:
Aggregate Functions: starcount(1)
-> Index Table Scan on t_idx.idx_policy
Filter Cond: prefix_between(__mo_index_idx_col)
For the equivalent >= / < range predicate, EXPLAIN also uses the secondary index table scan with serialized index-column predicates.
Expected Behavior
The indexed table should return the same result as MySQL and the MatrixOne non-indexed control table.
For the sample below, both indexed predicates should return 2.
Steps to Reproduce
DROP DATABASE IF EXISTS mysql_compat_idx_seed_mut_range;
CREATE DATABASE mysql_compat_idx_seed_mut_range;
USE mysql_compat_idx_seed_mut_range;
CREATE TABLE t_idx (
id varchar(64) not null,
user_id varchar(64) not null,
session_id varchar(64) not null,
policy varchar(32) not null,
due datetime(6) null,
primary key(user_id, session_id, id),
index idx_policy(policy, due, user_id, session_id, id)
);
CREATE TABLE t_no_idx (
id varchar(64) not null,
user_id varchar(64) not null,
session_id varchar(64) not null,
policy varchar(32) not null,
due datetime(6) null,
primary key(user_id, session_id, id)
);
INSERT INTO t_idx VALUES
('a1','u1','s1','keep','2030-01-01 00:00:00.000000'),
('a2','u1','s2','purge','2030-01-02 00:00:00.000000'),
('a3','u2','s1','key','2030-01-03 00:00:00.000000');
INSERT INTO t_no_idx SELECT * FROM t_idx;
SELECT 'idx_between' AS q, COUNT(*) AS cnt
FROM t_idx
WHERE policy BETWEEN 'kee' AND 'kez';
SELECT 'no_idx_between' AS q, COUNT(*) AS cnt
FROM t_no_idx
WHERE policy BETWEEN 'kee' AND 'kez';
SELECT 'idx_range' AS q, COUNT(*) AS cnt
FROM t_idx
WHERE policy >= 'kee' AND policy < 'kez';
SELECT 'no_idx_range' AS q, COUNT(*) AS cnt
FROM t_no_idx
WHERE policy >= 'kee' AND policy < 'kez';
SELECT 'idx_between_rows' AS q, id, policy
FROM t_idx
WHERE policy BETWEEN 'kee' AND 'kez'
ORDER BY id;
SELECT 'no_idx_between_rows' AS q, id, policy
FROM t_no_idx
WHERE policy BETWEEN 'kee' AND 'kez'
ORDER BY id;
EXPLAIN SELECT COUNT(*)
FROM t_idx
WHERE policy BETWEEN 'kee' AND 'kez';
EXPLAIN SELECT COUNT(*)
FROM t_idx
WHERE policy >= 'kee' AND policy < 'kez';Additional information
MySQL 8.0.45 result for the same SQL:
idx_between 2
no_idx_between 2
idx_range 2
no_idx_range 2
MatrixOne latest main result at 0e8602b78:
idx_between 0
no_idx_between 2
idx_range 0
no_idx_range 2
This is a deterministic wrong-result issue on a read query.
Activity
ck89119 commentedon Jul 2, 2026
Root cause analysis
This is not related to the VARCHAR type or the
prefix_betweenevaluation path. The actual trigger is that the secondary index parts explicitly contain all primary key columns (idx_policy(policy, due, user_id, session_id, id)covers PK(user_id, session_id, id)).PR #22053 introduced
getValidIndexesinpkg/sql/plan/bind_insert.go, which silently drops indexes covering the full primary key from the DML maintenance list (INSERT/DELETE/UPDATE/REPLACE). As a result the hidden index table__mo_index_secondary_*stays permanently empty (verified:COUNT(*)on the hidden table returns 0 after inserting rows), while the optimizer (apply_indices.go) still chooses that index for the Index Table Scan — so every query through the index path returns 0 rows. The evaluation layers (prefix_between, PK filter, zonemap) are all correct.Same root cause as #25341, #25345 and #25351.
Fixed by #25342
This has been fixed by #25342 (commit
2bf76218f, merged 2026-07-02), which restores DML maintenance for regular secondary indexes whenever their hidden table exists.Verified on latest
mainincluding2bf76218fwith the reproduction script from this issue:Also verified no regression on the original #22053 scenario: DELETE / UPDATE / REPLACE / ON DUPLICATE KEY UPDATE on covering secondary indexes (single-column and composite PK) all keep the index table consistent.
This issue can be closed as fixed by #25342.
Ariznawlll commentedon Jul 3, 2026
Verified on latest
main@2a8f3b884989(built locally from latestorigin/main).Validation result: fixed.
Compared with MySQL 8.0.45 using the repro from this issue:
The indexed table now matches the non-indexed control table and MySQL. This issue can be closed as fixed by #25342.
Ariznawlll commentedon Jul 3, 2026
Closing after verification on latest main @ 2a8f3b8: the repro now matches MySQL and the no-index control table. Fixed by #25342.
Ariznawlll commentedon Jul 3, 2026
Regression case added in matrixorigin/motr#39.
Case:
14_issue_regression.issue_25344_composite_index_varchar_rangeCommit:
0bf1ab1Target branch marker:
@target-branch: mainValidation on latest main passed with the composite-index regression group: