Repository navigation
Description
Summary
An IN lookup over the final column of a composite unique secondary index reads an entire 5,000-row run instead of probing the three requested keys. A single equality on the same (user_id, run_id, idempotency_key) index reads one base row. This is an observed performance problem; both forms return correct results in this reproduction.
Environment
- Disposable
matrixorigin/matrixone:4.2.8,VERSION()=8.0.30-MatrixOne-v4.2.8,GIT_VERSION()=10d204b. - Synthetic data only. Row counts below are
EXPLAIN ANALYZEoperator counts, not throughput or latency benchmarks.
Reproduction
Run on a fresh isolated database:
CREATE DATABASE mo_in_index_repro;
USE mo_in_index_repro;
CREATE TABLE digits (n INT PRIMARY KEY);
INSERT INTO digits VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
CREATE TABLE events (
id VARCHAR(64) NOT NULL, user_id VARCHAR(128) NOT NULL,
run_id VARCHAR(64) NOT NULL, session_id VARCHAR(64) NOT NULL,
event_idx BIGINT NOT NULL, event_type VARCHAR(64) NOT NULL,
idempotency_key VARCHAR(128), payload_json TEXT NOT NULL,
PRIMARY KEY (user_id,id),
UNIQUE KEY uq_user_run_key (user_id,run_id,idempotency_key),
KEY idx_session (user_id,session_id,run_id,event_idx),
KEY idx_type (user_id,run_id,event_type,event_idx)
);
INSERT INTO events
SELECT CONCAT('id',a.n+b.n*10+c.n*100+d.n*1000),
'target','long-run','session',a.n+b.n*10+c.n*100+d.n*1000,'tool_result',
CASE a.n+b.n*10+c.n*100+d.n*1000
WHEN 1 THEN 'user_intent:x'
WHEN 2 THEN 'user_intent_applied:x'
WHEN 3 THEN 'user_intent_returned:x'
ELSE CONCAT('event:',a.n+b.n*10+c.n*100+d.n*1000) END,
'{}'
FROM digits a CROSS JOIN digits b CROSS JOIN digits c CROSS JOIN digits d
WHERE a.n+b.n*10+c.n*100+d.n*1000 < 5000;
EXPLAIN ANALYZE SELECT payload_json,event_idx,session_id FROM events
WHERE user_id='target' AND run_id='long-run'
AND idempotency_key='user_intent:x';
EXPLAIN ANALYZE SELECT payload_json,event_idx,session_id FROM events
WHERE user_id='target' AND run_id='long-run' AND session_id='session'
AND idempotency_key IN ('user_intent:x','user_intent_applied:x','user_intent_returned:x');Observed and expected
- Equality selected
uq_user_run_key: base tableinputRows=1,outputRows=1. INselected a table scan:inputRows=5000,outputRows=3.UNION ALLof three equality point lookups selecteduq_user_run_keyin all three branches and returned the same three keys. On the larger application-shaped fixture, including the extrasession_idpredicate in each branch sometimes selected the less selective session index, so the application checks the returned session after the unique-key lookups before exposing any data.
Expected: a bounded set of exact keys on the fully specified composite unique index should use bounded point lookups, without work proportional to run history. FORCE INDEX did not repair the larger fixture. This is related to #32370, but here the leading composite key columns are fixed and the IN values are on the final unique-key column, within one user/run.
Astra context: matrixorigin/Astra#1243.
Activity
gouhongshen commentedon Nov 11, 2026
PR #32577 is trying to fix this issue.
fix(plan): use bounded key-set access for composite index IN prefixes (…
plan: bound composite unique index trailing IN lookups (#32577)
gouhongshen commentedon Nov 16, 2026
PR #32577 has merged and is awaiting manual validation. The issue remains open.
gouhongshen commentedon Nov 16, 2026
PR #32830 is trying to fix this issue.
fix: use bounded composite unique index key sets (#32830)
gouhongshen commentedon Nov 17, 2026
PR #32830 has merged and is awaiting manual validation. The issue remains open.
XuPeng-SH commentedon Nov 17, 2026
转 QA 验证,不代表验收通过,保持 issue 开放。
#32830 已于 2026-11-17 合入 main:
a7e743753131ba9867e0f7b4f5722f6c7e84afcc(head731df583b6176893f31e469a45df756beb617207),将 #32577 / #32567 的相关支持适配到 main。完整 full-value composite UNIQUE key 的其他部分等值、一个有限非 NULL 常量 IN 维度可生成精确去重 key set;候选上限为 128 points、1 MiB planning work、8 MiB wire data,拒绝准入时保留普通访问 fallback。验证证据按来源区分:
inputRows 证明该 fixture 工作量有界,不是延迟或吞吐 benchmark。动态值、含 NULL、多 IN 维度、declared prefix、错误 metadata、超资源限制等采用保守 fallback,并非承诺所有 IN 均走 key-set;仍须保持 SQL 语义。本轮只核对远端证据,没有在最终合并 SHA 自行实测。PR 所列 #32745 teardown/heartbeat flaky 与本修复独立,本 PR 没有修复它,不据此关闭该 issue。
请 QA 在最终 main 重跑本 issue 5,000 行原始查询与 equality 对照,核对结果、索引选择和实际 input/output rows;覆盖重复/不存在 key、NULL 三值逻辑、prepared reuse、残余与 backfill、index-only、竞争索引/缺统计、hint/prefix 安全,及 128 点、字节/预算边界、取消、重试和 fallback。补多 CN 与实际规模的延迟/吞吐验证,但未测性能不作为阻转条件。不自动要求或执行 backport。
已读完整 issue/PR 评论和评审,未见当前适用的已验证反例或未完开发 follow-up。按持续交接流程移除原研发负责人,改派唯一 @Ariznawlll。
slyunnn commentedon Nov 19, 2026
Regression and extended verification for #32410 (2026-11-19)
Verification Environment
main: latest fetchedae9e665f3093094ba3286e72bf1af8e111463180,perf(exec): reduce accounted work on short index range scans (#32895); fix fix: use bounded composite unique index key sets #32830, mergea7e743753131ba9867e0f7b4f5722f6c7e84afcc.4.2-dev: latest fetched71e22339c8cca62b2f29f9fd6e686e653a1ff2d2,[4.2-dev] fix(frontend): preserve string literals in merged role rules (#32891); fix plan: bound composite unique index trailing IN lookups #32577, mergedec4ce9772e281203d70c390a74bce0937c39ee6.2 CN / 1 TN / 1 Log / Proxycluster. Proxy6001, CN116001and CN216002were reachable. The original SQL and extended product test ran on every endpoint over JDBC/MySQL protocol. Branches and cases were executed serially; no engine-parallel claim is made.What Was Covered
5,000-row fixture and equality control, actualEXPLAIN ANALYZEplan assertions and result checks on each endpoint. The unique index was selected; the original three-keyINquery's base scan reportedinputRows=3,outputRows=3, while equality reported1/1.optimizer/composite_unique_in_index.sql:main56/56and4.2-dev55/55on each of Proxy, CN1 and CN2, with no failed or ignored statements. It covers duplicate/absent keys, NULL semantics, prepared reuse, residual predicates and base-row backfill, forced index, prefix indexes and competing/missing-statistics controls.TestCompositePointCandidateandTestCompositeUnique*planner tests passed on both branches, including bounded point counts, encoded-byte budget and fallback. These are planner tests, not live latency benchmarks.5,000-row fixture is required to show bounded scan work for the reported regression; operator row counts do not establish a production performance SLA.Findings
The original query returned the expected keys and used bounded access on both maintenance branches at the tested commits.
MOTR / BVT Coverage
Existing product BVT directly covers the original SQL, plan and result boundaries on both branches, so an additional duplicate MOTR case is unnecessary. No Nightly performance workflow was added.
Final Conclusion
Fixed on the tested
mainand4.2-devrevisions for the reported bounded-scan regression.