Repository navigation
Description
Is there an existing issue for the same bug?
I searched open and closed MatrixOne issues/PRs for prefix indexes, index-only scans, secondary-index substring handling, and the 191-character boundary.
This is distinct from:
- [Bug]: VARBINARY index-only equality treats empty and NUL values as prefixes #26807 / fix binary secondary-index point lookup semantics #26809: exact VARBINARY equality is confused by a non-self-delimiting encoded prefix. This reproduction uses ordinary VARCHAR and fails because the physical prefix index intentionally stores a lossy substring.
- [Bug]: TEXT column cannot be in any index, including prefix index (v3.0.11 & 4.0-dev) #24740 / fix(plan): support enum and prefix text indexes #24809: those added TEXT/BLOB prefix-index DDL and DML support. Their queries require base-table backfill and therefore do not exercise a covering/index-only projection.
- [Bug]: VARCHAR range predicates return zero rows through composite secondary index #25344 / [Bug]: Index-only aggregates over composite secondary indexes return zero or NULL #25348: those concern ordinary composite secondary-index range/aggregate rewrites, not an explicitly declared prefix index.
Branch Name
main
Commit ID
08770e1beeb23239c91165492f2fe85243a3c66a
Other Environment Information
- Local single-node MatrixOne on Linux
- Built from the commit above with Go 1.26.4
- MySQL client against port 6001
- Reproduces before and after an explicit TN flush
Actual Behavior
A covering query through a VARCHAR prefix index silently drops a row as soon as the stored value is longer than the declared prefix. The equivalent query that disables the index returns the row.
The boundary is exact for INDEX idx_p(s(191)):
value length FORCE INDEX count IGNORE INDEX count
190 1 1
191 1 1
192 0 1
A query that also projects a non-indexed payload and therefore performs base-table backfill returns the correct row. The hidden index is populated, and serial_extract(__mo_index_idx_col, 0, VARCHAR) confirms that only 191 characters are stored. This isolates the defect to the covering/index-only read path rather than index maintenance.
Expected Behavior
An explicitly declared prefix index is a lossy candidate structure. It may narrow base-table rows, but it must not be used as the source of the complete column value. Forced/default index selection must return the same SQL result as a base-table scan.
Steps to Reproduce
CREATE DATABASE prefix_covering_repro;
USE prefix_covering_repro;
CREATE TABLE t (
id INT PRIMARY KEY,
s VARCHAR(400) NOT NULL,
payload VARCHAR(32) NOT NULL,
INDEX idx_p(s(191))
);
INSERT INTO t VALUES
(190, CONCAT(REPEAT('a',189),'0'), 'n-1'),
(191, CONCAT(REPEAT('b',190),'1'), 'n'),
(192, CONCAT(REPEAT('c',191),'2'), 'n+1'),
(193, CONCAT(REPEAT('c',191),'3'), 'same-prefix-control');
SELECT COUNT(*) FROM t FORCE INDEX(idx_p)
WHERE s=CONCAT(REPEAT('a',189),'0');
-- 1
SELECT COUNT(*) FROM t IGNORE INDEX(idx_p)
WHERE s=CONCAT(REPEAT('a',189),'0');
-- 1
SELECT COUNT(*) FROM t FORCE INDEX(idx_p)
WHERE s=CONCAT(REPEAT('b',190),'1');
-- 1
SELECT COUNT(*) FROM t IGNORE INDEX(idx_p)
WHERE s=CONCAT(REPEAT('b',190),'1');
-- 1
SELECT COUNT(*) FROM t FORCE INDEX(idx_p)
WHERE s=CONCAT(REPEAT('c',191),'2');
-- wrong: 0
SELECT COUNT(*) FROM t IGNORE INDEX(idx_p)
WHERE s=CONCAT(REPEAT('c',191),'2');
-- correct: 1
SELECT id,payload FROM t FORCE INDEX(idx_p)
WHERE s=CONCAT(REPEAT('c',191),'2');
-- correct through an INDEX join + base-table residual: 192, n+1
SELECT mo_ctl('dn','flush','prefix_covering_repro.t');
SELECT SLEEP(1);
SELECT COUNT(*) FROM t FORCE INDEX(idx_p)
WHERE s=CONCAT(REPEAT('c',191),'2');
-- still wrong: 0The same index-only failure reproduces with multibyte Unicode values and with a 301-character value behind a 191-character prefix.
Additional Information
The DML path correctly materializes the declared substring in appendIndexPrefixProjection. The read optimizer's tryIndexOnlyScan only checks whether a referenced column name appears in IndexDef.Parts; it does not account for IndexAlgoParams declaring that the stored part is truncated. It then maps the logical column to serial_extract(__mo_index_idx_col, ...), treating the lossy prefix as the full value.
The safe invariant is: an index with any declared prefix length may still feed an INDEX join, but cannot satisfy a covering/index-only projection unless the full source value is available elsewhere.
Please retain both black-box and white-box coverage:
- public SQL at
N-1,N, andN+1, including a same-prefix neighbor, Unicode, flush, covering aggregate/projection, and a backfill control; - a planner assertion that
tryIndexOnlyScanrejects anIndexDefwhose persisted prefix-length metadata is non-empty while the ordinary non-prefix control remains eligible.
Activity
fix(plan): make prefix index equality lookups lossless (matrixorigin#…
fix(plan): make prefix index equality lookups lossless (matrixorigin#…
fix: harden regular prefix index correctness (#26829)
LeftHandCold commentedon Aug 11, 2026
Validation result — fixed by #26829.
Verified on the exact merge commit
ac339444b558daf2c3d7fe63f755743449db7696, against the original08770e1baseline.Baseline: FORCE INDEX lost values longer than the declared prefix (including after TN flush) and could return truncated values through a covering/order path.
Fix verification: FORCE and IGNORE returned the same full result for the original reproduction, the 191-character N-1/N/N+1 boundary, same-prefix neighbours, Unicode values, projection/order, and post-flush reads. EXPLAIN shows a prefix equality candidate lookup with the original full predicate retained on the base table; lossy prefix indexes no longer serve index-only reconstruction.
Focused and complete
pkg/catalog+pkg/sql/plantests passed, together with the PR BVT coverage.Conclusion: the reported correctness defect is fixed. Closing.
fix: harden regular prefix index correctness (matrixorigin#26829)
fix: harden regular prefix index correctness (matrixorigin#26829)
fix: harden regular prefix index correctness (matrixorigin#26829)