Repository navigation
Description
Description
In MySQL, col LIKE 'abc%' is optimized into a range scan on any B-tree index over col (prefix match → [abc, abd)). In MatrixOne, the same predicate never uses a secondary index — even when the indexed column is exactly the LIKE's subject and the pattern is a literal prefix:
CREATE TABLE full_idx (id INT PRIMARY KEY, name VARCHAR(100), KEY k_full(name));
EXPLAIN SELECT * FROM full_idx WHERE name LIKE 'aaaaaaaaaa%';MO plan:
Project
-> Table Scan on fidx.full_idx
Filter Cond: prefix_eq(full_idx.name)
Block Filter Cond: prefix_eq(full_idx.name)
The optimizer clearly recognizes the predicate as a prefix condition — the internal prefix_eq node appears in the filter — but the plan is a bare table scan with no Index Table Scan.
Controls proving this is a missing rewrite, not a general index-usage fault:
| predicate | plan |
|---|---|
name LIKE 'aaaaaaaaaa%' |
Table Scan only (prefix_eq in filter) |
name >= 'aaaaaaaaaa' AND name < 'aaaaaaaaba' (manual equivalent range) |
Index Table Scan on k_full with prefix_in_range + serial_extract bounds ✓ |
name = 'aaaaaaaaaaXXXXXXXX' |
Index Table Scan on k_full ✓ |
LEFT(name,10)='aaaaaaaaaa' |
Table Scan (functional-expr path not rewritten either; separate surface) |
So the index, the range-lowering machinery, and equality binding all work; only the LIKE 'prefix%' → range rewrite is absent. Same behavior with a prefix-limited index (KEY (name(10))).
Reproduction
CREATE TABLE t (id INT PRIMARY KEY, name VARCHAR(100), KEY k(name));
INSERT INTO t VALUES (1,'aaaaaaaaaaXXXXXXXX'),(2,'bbbbbbbbbbYYYYYYYY');
EXPLAIN SELECT * FROM t WHERE name LIKE 'aaaaaaaaaa%'; -- Table Scan, no index
EXPLAIN SELECT * FROM t WHERE name >= 'aaaaaaaaaa' AND name < 'aaaaaaaaba'; -- Index scanImpact
- Any application using
LIKE 'prefix%'for autocomplete / name search / pagination on an indexed column silently degrades from index range scan to full table scan. On large tables this is a performance cliff that differs from MySQL. - The presence of
prefix_eqin the plan shows partial intent existed; the rewrite to index range was just never wired.
Expected behavior
A literal-anchored LIKE 'prefix%' over an indexable column should compile to the same index range scan the manual >= / < range produces (matching MySQL's range access type).
Activity
Ariznawlll commentedon Oct 30, 2026
结论
测试不通过。当前 main 的前缀 LIKE 仍走表扫描,而等价范围条件可使用同一索引;本轮结果正确,问题是访问路径及额外扫描。
关键证据
main@d39d8a40343ccd40bf665036388df7a40ee867f8,隔离双 CN / 单 TN;按本 issue 的原始两行 SQL 在 3 个新库复测,3/3 得到同样的表扫描与索引扫描计划,结果均为第一行。LIKE 'abc%'与name >= 'abc' AND name < 'abd'各交替执行 6 次:MO 与 MySQL 8.3 的计数和 ID 求和均一致。MO 前者走表扫描、后者走索引;MySQL 两者均使用 range 索引。MO 本机暖缓存中位数分别约 4.94–5.16 ms 和 0.98–3.01 ms,不能作为生产 SLA。待解决点
XuPeng-SH commentedon Nov 2, 2026
duplicate with #31867