Repository navigation
Description
Parent issue
This is a sub-issue of #27665: significant gap in ClickBench query performance between MatrixOne and DuckDB.
Summary
ClickBench Q10 shows a significant MatrixOne performance gap against the DuckDB reference. The values below are elapsed seconds. Each result array is the three measurements emitted by the adapter: [run 1, run 2, run 3]; warm median is the median of the available run-2/run-3 values.
Query
SELECT RegionID, SUM(AdvEngineID), COUNT(*) AS c, AVG(ResolutionWidth), COUNT(DISTINCT UserID) FROM hits GROUP BY RegionID ORDER BY c DESC LIMIT 10;Performance comparison
| Engine | Run 1 | Run 2 | Run 3 | Warm median |
|---|---|---|---|---|
| MatrixOne | 735.600 | 751.040 | failed (null) | 751.040 |
| DuckDB | 2.462 | 0.512 | 0.483 | 0.497 |
- MatrixOne / DuckDB warm-median ratio: 1509.63x
- Warm-median difference: 750.543 seconds
- Raw MatrixOne timing array:
[735.600, 751.040, null] - Raw DuckDB timing array:
[2.462, 0.512, 0.483]
Environment and data
MatrixOne measurement:
- Branch:
main - Commit:
249a458ba567b26d1818fb0496b449135cb05ef2 - Hardware:
server 129 - OS: CentOS
- Dataset: ClickBench
hits, 99,997,497 rows - MatrixOne raw output:
/mnt/fastdata/ClickBench/matrixone/raw_results.md
DuckDB reference:
- Result file:
duckdb/results/20260511/c6a.metal.json - Machine label:
c6a.metal - Result date:
2026-05-11
The two measurements were not collected on the same hardware. The DuckDB value is the latest local c6a.metal reference available; an apples-to-apples rerun on the same server is recommended before assigning a final performance regression magnitude.
Steps to reproduce
- Follow the reproduction steps in #27665, including the MatrixOne and DuckDB adapter READMEs:
- Use the same
hits.tsv.gzdataset for both engines (the adapters support loading the gzip file directly). - In the MatrixOne adapter, run
./benchmark.shafter settingMATRIXONE_HOME,MATRIXONE_DATA_FILE,MATRIXONE_HOST,MATRIXONE_PORT,MATRIXONE_USER, andMATRIXONE_PASSWORDas described in [Bug]: significant gap in clickbench query performance between matrixone and duckdb #27665. - In the DuckDB adapter, run
./benchmark.shafter settingDUCKDB_BIN_PATH,DUCKDB_DB_PATH, andDUCKDB_DATA_PATHas described in the README. - Compare the Q10 entry in
queries.sql; run the query three times after loading the data and record elapsed time and whether the query completes successfully.
Notes
- MatrixOne has one failed measurement (
ERROR 2013 (HY000): Lost connection to MySQL server during query); the third value is shown asnull.
Expected behavior
On comparable hardware with the same dataset, MatrixOne should not exhibit a large query-level performance gap for this workload. Please investigate the execution plan, operators, memory use, and any spill or connection/timeout behavior relevant to this query.
Activity
XuPeng-SH commentedon Aug 26, 2026
55 机器上的最小复现(2026-08-26)
Q10 是 ClickBench 聚合查询,不是 TPC-H Q10:
为避免使用 1 亿行原始 ClickBench 数据,在 55(MatrixOne
8.0.30-MatrixOne-v4.0.0-rc4,SQL 端口 6001,单 CN 16 cores)建立了独立的最小投影表。Q10 实际只读取以下 4 列,列式扫描下这可以隔离聚合问题:数据特征:1,000,000 行、100 个 RegionID、1,000,000 个 UserID(每个 region 约 10,000 个 distinct user)。
实测热查询耗时:
COUNT(DISTINCT UserID):约 0.013 秒COUNT(DISTINCT UserID):约 0.02–0.03 秒GROUP BY RegionID, COUNT(DISTINCT UserID):约 0.03 秒GROUP BY RegionID, SUM(AdvEngineID), COUNT(DISTINCT UserID):约 8.2 秒EXPLAIN ANALYZE将耗时定位到 Aggregate,而不是扫描、排序或返回结果:对照计划显示,只有 DISTINCT 时会生成
GROUP BY RegionID, UserID的两阶段聚合;混合普通聚合时则保留单个分组 Aggregate,导致每一行同时维护分组内 DISTINCT 状态。当前optimizeDistinctAgg对AggList长度大于 1 直接跳过改写,这与 Q10 的形状正好吻合。因此这个最小数据集已经稳定复现 issue 的慢路径;1 亿行的 751 秒是该路径在更大输入和更高 distinct 基数下的规模放大,不能仅归因于磁盘或连接超时。该结果是同机实测,合成数据不用于宣称与 ClickBench 绝对倍数相同。
perf: linearize DISTINCT aggregate preflight deduplication (#27688)
perf: parallelize high-cardinality mixed DISTINCT aggregation (#27693)
XuPeng-SH commentedon Aug 27, 2026
Update: mixed aggregation slow path fixed by #27693
#27693 (
perf: parallelize high-cardinality mixed DISTINCT aggregation) is now merged. It addresses the root cause identified in the minimal reproduction: a mixed aggregate containing mergeableCOUNT(DISTINCT ...)was costed only by the finalGROUP BYcardinality. With a modest number of final groups, the planner did not distribute ownership of complete groups, leaving expensive exact DISTINCT state merges on the critical path.The fix preserves exact DISTINCT semantics and changes the topology only when the retained exact DISTINCT state is material relative to the input:
COUNT(DISTINCT ...)state cardinality in addition to final group cardinality;COUNT(DISTINCT)queries with enough active groups, shuffle by a group key so every logical group has one aggregate owner;10 million-row isolated validation on 55
The following is the same reduced Q10 shape used for diagnosis, scaled to 10,000,000 rows on the existing NVMe-backed isolated table: 100 balanced
RegionIDvalues and 10,000,000 uniqueUserIDvalues.This is a 43x reduction on the same data and machine. The execution plan uses a 16-core distributed aggregate topology; runtime sampling showed about 11–12 CPU cores in use during the query. The machine also had unrelated
mo-serviceprocesses running, so this result is intentionally reported as a same-host before/after comparison rather than a clean-host absolute latency claim.The result confirms that the issue's observed multi-aggregate Q10 regression was caused by aggregate-state ownership/merge topology, rather than the scan, sort, client, or storage path. The prior 1 million-row diagnosis remains a smaller reproducer of the same root cause.
Scope remaining after the fix
This fix obtains parallelism from complete final-group ownership. It is therefore the correct fast path for many balanced groups, but cannot fully parallelize these shapes:
Those cases need partitioning by the canonical DISTINCT identity
(group keys, DISTINCT arguments), not only by final group key. They also need a bounded-memory path when one group's exact state exceeds memory.This issue remains open until the original full ClickBench-scale workload has been re-run on the merged revision under a controlled, comparable environment and the remaining single-hot-group/memory boundaries have been separately covered.
XuPeng-SH commentedon Sep 1, 2026
2026-09-01 candidate diagnosis
SQL shape: low-cardinality RegionID grouping with SUM/COUNT/AVG plus exact COUNT(DISTINCT UserID), followed by a tiny TopN.
Confirmed historical cause / current-main status: #27693 was merged specifically for this issue after the recorded baseline. It addresses the planner ignoring the large retained DISTINCT state, the serial MergeGroup path, and expensive ordered-state growth/merge. The historical third run also lost the server connection, so 751s is a reliability signal as well as a stale performance number.
Next action: re-run current main and require: exact results; three successful runs; post-query service health; no unexpected serial MergeGroup; balanced aggregate owners; bounded memory/spill; and DOP scaling. If a hot/few-group residual remains, route it to canonical (RegionID, UserID) partitioning in #27720.
Do not optimize TopN first: all expensive work occurs before the ten RegionID results exist.
perf(aggexec): accelerate fixed-width COUNT(DISTINCT) (#28431)
perf: linearize DISTINCT aggregate preflight deduplication (matrixori…
perf: parallelize high-cardinality mixed DISTINCT aggregation (matrix…
perf(aggexec): accelerate fixed-width COUNT(DISTINCT) (matrixorigin#2…
perf: linearize DISTINCT aggregate preflight deduplication (matrixori…
perf: parallelize high-cardinality mixed DISTINCT aggregation (matrix…
perf(aggexec): accelerate fixed-width COUNT(DISTINCT) (matrixorigin#2…
perf: linearize DISTINCT aggregate preflight deduplication (matrixori…
perf: parallelize high-cardinality mixed DISTINCT aggregation (matrix…
perf(aggexec): accelerate fixed-width COUNT(DISTINCT) (matrixorigin#2…
[4.2-dev] perf: backport COUNT(DISTINCT) optimizations (#27693, #28431)…
XuPeng-SH commentedon Nov 18, 2026
转 QA:ClickBench Q10 混合 DISTINCT 聚合修复
@Ariznawlll 请接手验证。本 issue 保持 open;这是修复交接,不代表验收通过,也不代表原始 ClickBench 性能差距已全部消除。
修复与证据
main,merge SHAdfef35f7dd94de507d40dd18082b64e7f4b84e40。修复针对混合 SUM/COUNT/AVG 与高基数COUNT(DISTINCT UserID)的状态成本估计、分组所有权及串行 exact-state 合并慢路径。19ee0241dd22453de010225225d937988d642648修正,原 reviewer 后续 APPROVED 明确认定 blocker 已解决;旧 inline thread 的 unresolved 标记本身不构成未解决反例。待验证范围与边界
4.2-dev的 [4.2-dev] perf: backport COUNT(DISTINCT) optimizations (#27693, #28431) #32646(94dd363428668861bd0c8e60a197a115e950a1ce),其说明为 perf: parallelize high-cardinality mixed DISTINCT aggregation #27693 与 perf(aggexec): accelerate fixed-width COUNT(DISTINCT) #28431 的组合适配。请按实际待验分支分别记录版本,勿把 main 的历史结果直接等同于 4.2 验收;PR 作者报告真实三 CN 正常/race fixture;reviewer 在a717091e1d8437911f8e90a17463d18ea668ee5a上独立确认三 CN fixture 正常执行、arena/aggregate race 及 14 个新增根测试各 100 次 race。最终 head85d603b1b23af625eb60a6d8db8c0e8ccb569749的后续 review 记录为 interrupted,不能把早期 review 冒充最终 head 重验。局部 warm benchmark(fill 46.86→4.99 ms、merge 43.10→4.29 ms)不是完整 Q10 性能。4.2 不含 DISTINCT spill 或后续 main accounting,保留共享内存上限,无 per-query/tenant 隔离内存保证,升级要求全停。本次没有执行 backport,也不声称生产规模或升级验收已完成。写前已重新读取本 issue 的完整评论与时间线,未发现新增的修复后失败记录或当前必需的开发修复说明。