Repository navigation
Description
Is there an existing issue for performance?
- I have checked the existing issues.
Environment
- Version or commit-id:
mainat946427b877c1b12c497743eff264047e60a00be2 - Deployment: two-CN
make dev-upcluster - Hardware parameters: 24 CPU cores; 6 GiB file-service memory cache per CN
- OS type: Linux
Details of Performance
A correlated scalar subquery can be flattened into a right SINGLE hash join when the preserved outer relation is much smaller than the inner table:
CREATE DATABASE rsingle_perf;
USE rsingle_perf;
CREATE TABLE big(id BIGINT PRIMARY KEY, v BIGINT);
INSERT INTO big
SELECT result, result * 10
FROM generate_series(1, 1000000, 1);
CREATE TABLE small(id BIGINT PRIMARY KEY);
INSERT INTO small VALUES (1), (5000000), (10000000);
ANALYZE TABLE big;
ANALYZE TABLE small;
SELECT s.id,
(SELECT b.v FROM big b WHERE b.id = s.id) AS v
FROM small s
ORDER BY s.id;The optimizer physically swaps the scalar SINGLE join so that the small preserved relation is the hash-build side and big is the probe table:
Join Type: RIGHT SINGLE
Join Cond: (b.id = s.id)
├── Table Scan: big -- probe; unmatched rows are discarded
└── Table Scan: small -- build and preserved side
On main, generateRuntimeFilters rejects every Node_SINGLE join. As a result, the query scans and probes all rows from big, even though the build side contains only three keys.
A one-CN prototype that generates a runtime filter only for right SINGLE reduced the work as follows:
Metric from EXPLAIN ANALYZE |
Main-equivalent path (RF disabled) | Right-SINGLE RF prototype |
|---|---|---|
big input blocks |
123 | 1 |
big input rows |
1,000,000 | 1 |
| Join input rows | 1,000,003 | 4 |
| Scan read size | 7.68 MiB | 96.33 KiB |
| Warm-cache client latency | 0.21 s | 0.21 s |
The warm-cache latency at this scale is dominated by fixed/client overhead, but the avoided scan, I/O, and hash-probe work is substantial and should matter for larger/wider tables, cold cache, and concurrent workloads.
Important multi-CN constraint
Simply allowing Node_SINGLE && IsRightJoin through the existing runtime-filter gate is not safe.
With the same one-million-row data set forced onto the multi-CN execution path:
| Optimizer settings | Result |
|---|---|
runtimeFilter=1,execType=3 (RF disabled) |
Completed correctly in 0.23 s |
execType=3 (naive right-SINGLE RF enabled) |
Did not finish after 37.10 s; canceled manually with context canceled |
A natural ten-million-row AP multi-CN plan with the naive RF also failed to finish after more than 80 seconds. Therefore, this issue must not be fixed by only relaxing the join-type check. The right-SINGLE runtime-filter message/scheduling lifecycle must work across CNs, or the eligible plan must be safely constrained to one CN.
Expected behavior / acceptance criteria
- Eligible right
SINGLEjoins can filter a discardable table-scan probe using keys from the preserved build side. - Left
SINGLEjoins remain excluded because unmatched probe rows must be preserved. - Existing runtime-filter eligibility guards remain effective, including non-leading composite-primary-key checks and cardinality/selectivity limits.
- Scalar-subquery semantics remain correct for matching keys, missing keys (
NULL), and duplicate inner matches (cardinality violation). - Both one-CN and multi-CN executions finish without hangs and return identical results with the optimization enabled or disabled.
- A multi-CN BVT/regression test covers the runtime-filter message lifecycle, not only the presence of Build/Probe specs in the logical plan.
EXPLAIN ANALYZEdemonstrates reduced probe blocks/rows on a large-table/small-build case.
Additional information
The right-SINGLE output-cardinality calculation has a separate optimizer-phase concern: IsRightJoin is set before swapJoinChildren, while the physical child order changes later. A generic cardinality change based only on IsRightJoin can be correct after the swap but wrong during earlier join-ordering passes. That change should not be bundled into this performance fix without a phase-safe preserved-side model and a downstream-join plan regression test.
Activity
XuPeng-SH commentedon Jul 18, 2026
Latest-main SQL-shape verification
I reproduced the issue directly with a clean image built from
maincommit946427b877c1b12c497743eff264047e60a00be2. Both CNs in the two-CNmake dev-upcluster were replaced with that image while keeping the same TN, LogService, and data. The test used:customer: 1,000,000 rows, primary keyidproduct: 1,000,000 rows, primary keyiddelta/ DML target: 3 rows with sparse lookup keysNo experimental runtime-filter code was present in the main image.
Confirmed affected SQL shapes
EXPLAIN ANALYZERIGHT SINGLERIGHT SINGLERIGHT SINGLEjoinsUPDATE ... SETRIGHT SINGLEunderMulti UpdateINSERT ... SELECTRIGHT SINGLEunderLockandDEDUPRIGHT SINGLEunderFilterandMulti UpdateRepresentative SELECT:
Latest-main runtime evidence:
The multiple-lookup case independently scanned both million-row tables:
DML correctness and scan amplification
The DML statements completed correctly:
Verified results:
Each statement nevertheless fed
1,000,003rows into the right-SINGLE join to produce only 3 rows. Thus this is a performance/resource-amplification issue, not a result-correctness failure.One-CN prototype comparison
With the right-SINGLE runtime-filter prototype enabled on the same data and SQL shapes:
All output/DML results remained identical in the one-CN tests. This confirms that the optimization opportunity is real across SELECT and DML shapes. It does not remove the multi-CN safety requirement documented in the issue: the naive prototype still stalls on the multi-CN execution path and is not mergeable as-is.
Negative controls
The following did not produce
SINGLEand are outside this issue's specific scope:MAX(...)scalar subquery:RIGHTjoin with aggregateEXISTS:SEMIjoinThe test database was removed after verification, optimizer hints were restored, both CNs were switched back to the local development image, and all five cluster services are healthy.
perf(plan): prune right SINGLE probe scans with runtime filters (#25865)
Ariznawlll commentedon Aug 26, 2026
测试环境
main,commit946427b877c1b12c497743eff264047e60a00be2复现步骤
创建两张百万行 lookup 表和一个只有 3 行的稀疏输入表:
执行代表性标量子查询并查看实际执行:
继续执行以下 SQL,覆盖 SELECT、UPDATE、INSERT ... SELECT 和 DELETE:
对每条语句检查
EXPLAIN ANALYZE的 Right SINGLE 节点、输入行数、扫描 block 数和最终输出行数;同时核对 DML 结果。实际结果
RIGHT SINGLE,customer 扫描约 123 blocks / 1,000,000 rows,最终只输出 3 行。期望结果
对于只有 3 个 lookup key 的输入,Right SINGLE 应通过 runtime filter 将 probe 扫描限制在命中 key 的少量行,并保持双 CN 执行安全;不应扫描整张百万行 probe 表。
测试结论
测试不通过。
perf: enable right SINGLE filters for local queries without stats (#2…
perf(plan): prune right SINGLE probe scans with runtime filters (matr…
perf: enable right SINGLE filters for local queries without stats (ma…
perf(plan): prune right SINGLE probe scans with runtime filters (matr…
perf: enable right SINGLE filters for local queries without stats (ma…
perf(plan): prune right SINGLE probe scans with runtime filters (matr…
perf: enable right SINGLE filters for local queries without stats (ma…
XuPeng-SH commentedon Sep 22, 2026
Current-main reconciliation: this issue's implementation is already present through #25865 (merge
862d9d30c2) and follow-up #27626 (merge1891117aed); both are ancestors of currentmain(3727c5c543).The merged behavior is intentionally conservative:
SINGLEjoins can build an exact runtime filter for the discardable probe side;SINGLE, unsafe scan shapes, unsupported keys, and over-limit builds retain the fallback;PASSwhile preserving the complete JoinMap.Fresh checks on the current main revision passed for the right-SINGLE planner contracts, bounded hashbuild fallback/cardinality, and compile topology/parallel-producer validation. #27626 also records the original isolated two-CN acceptance run and scan reduction (1,000,000 probe rows to 2 rows in the eligible local plan, with forced multi-CN completing on the no-filter fallback).
I found no reachable current-main code gap and therefore did not create a duplicate PR. I have not rerun the live one-CN/two-CN BVT and EXPLAIN ANALYZE profile on
3727c5c543, so that historical live evidence should not be treated as a fresh execution on today's SHA. Subject to that validation distinction, this issue is code-complete via the two merged PRs.Ariznawlll commentedon Oct 3, 2026
测试版本
main529ee099e32ed8c38d2806043bf1516ab0345e45原问题验证
在 100 万行的 probe 表和 4 个稀疏查找键下,对 RIGHT SINGLE 标量子查询连续运行 3 轮,逐轮检查完整查询结果及
EXPLAIN ANALYZE:正常路径只扫描 3 行 / 3 blocks;关闭 Right SINGLE runtime filter 的对照路径扫描 1,000,000 行 / 128 blocks。两条路径返回的标量子查询结果一致。该差异直接证明命中的本地计划确实过滤了大表扫描,而不只是计划文本出现 Build/Probe 标记。正常路径覆盖
边界与错误路径覆盖
1242cardinality error,而不是选取任意一行或写出部分 DML 结果。白盒验证
本轮以公开 SQL、
EXPLAIN ANALYZE和双 CN 完成性为主,未新增故障注入。实现及边界的 Go 测试来自已合入的 #25865 与 #27626。回归测试
main的对应 job 为success;整个 workflow 的其他失败不代表此用例失败。测试证据
测试结论
测试通过。