Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
Other Environment Information
- Isolated MatrixOne single-node runtime; every formal run returned
git_version()='98b20975'andSELECT 42=42. GOMAXPROCS=4,GOMEMLIMIT=4GiB; no system-variable, hint, or admission-control changes.- Two independent formal runs at N=8,192 and N=16,384, with a 32-row build side and eight 256-byte
LONGTEXTcolumns on the probe side. Each arm executed 20 result-checked statements under a 20-second symbolized CPU profile. - Exact 32*N-pair aggregates,
EXPLAIN,EXPLAIN PHYPLAN ANALYZE, direct source-line pprof, and owned-database cleanup passed at both scales. - This is a structural executor-path and sampled-CPU report, not a wall-clock-speedup claim. The exact Product control is specific to this always-true predicate fixture and is not a general join rewrite.
Actual Behavior
Generic conditioned LoopJoin evaluation stages each probe row by replicating every probe input vector, including wide columns that the join condition never references. SetJoinBatchValues loops over the entire input batch and invokes a const-set function for every vector before evaluating the residual expression.
In this fixture the condition references only a.id, a.v, and b.v, but staging also replicates a.p0 through a.p7 for every build row. The target uses generic LoopJoin; the exact control uses Product. Both scan the same N/32 rows and return the same aggregate over exactly 32*N pairs.
Direct symbolized CPU attribution:
| Formal N | Target loopjoin/probe.go:217 |
Target evalExpression.go:2435 |
Control samples on both lines |
|---|---|---|---|
| 8,192 | 410ms | 410ms | none |
| 16,384 | 790ms | 790ms | none |
Exact results:
| N | Pair count | SUM(a.id) |
Each of eight SUM(LENGTH(a.pX)) |
Identical result SHA-256 |
|---|---|---|---|---|
| 8,192 | 262,144 | 1,073,872,896 | 67,108,864 | b8ec98ee90ed7b686b03834cdad81addcec2426a44f062ea2fec10ecf8377141 |
| 16,384 | 524,288 | 4,295,229,440 | 134,217,728 | 021bf54ded9c5c2c75b841cb9e442d98a5d9c94afe17ed2a715183360f6b4abf |
At N=16,384 the target physical plan has loop join ... InRows:16384 OutRows:524288; the aggregate consumes 524,288 rows and emits one. Both base scans retain their exact N-row and 32-row cardinalities. The direct target call chain is evalConditionWindow → SetJoinBatchValues; the control has no condition-staging samples.
Expected Behavior
Generic LoopJoin should stage only probe columns required by the residual condition, or otherwise evaluate the expression without materializing unused wide columns for every build row.
A guarded implementation must preserve:
- Expression column references and type/cast/collation semantics after any projection or remapping.
- The specialized
PairConditionfast path; this request concerns only the generic path wherePairCondition == nil. - Condition-window bounds, vector lengths, NULL handling, selection/order semantics, and join output cardinality.
- Vector ownership, const-set behavior, join-batch reuse, window cleanup, cancellation, and error paths.
This report does not propose removing residual predicates or replacing generic LoopJoin with Cross Join. The Product query below is only an exact control because this fixture makes every target predicate true.
Steps to Reproduce
The following uses local SQL endpoint 127.0.0.1:16001 (root/111) and pprof endpoint 127.0.0.1:16011; substitute local values as needed. Use only an owned disposable database.
1. Create the probe and build fixtures
Choose N=8192, then repeat the complete procedure with N=16384:
DROP DATABASE IF EXISTS repro_n2;
CREATE DATABASE repro_n2;
USE repro_n2;
CREATE TABLE probe_rows(
id BIGINT PRIMARY KEY,
v BIGINT NOT NULL,
p0 LONGTEXT NOT NULL,
p1 LONGTEXT NOT NULL,
p2 LONGTEXT NOT NULL,
p3 LONGTEXT NOT NULL,
p4 LONGTEXT NOT NULL,
p5 LONGTEXT NOT NULL,
p6 LONGTEXT NOT NULL,
p7 LONGTEXT NOT NULL
);
CREATE TABLE build_rows(
id BIGINT PRIMARY KEY,
v BIGINT NOT NULL
);Populate with Python 3/PyMySQL, passing N as the only argument:
import pymysql
import sys
n = int(sys.argv[1])
assert n in (8192, 16384)
payload = "p" * 256
conn = pymysql.connect(
host="127.0.0.1", port=16001, user="root", password="111",
database="repro_n2", autocommit=True, charset="utf8mb4",
)
with conn.cursor() as cur:
for begin in range(1, n + 1, 250):
end = min(n, begin + 249)
cur.executemany(
"INSERT INTO probe_rows VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
[(i, 0, *([payload] * 8))
for i in range(begin, end + 1)],
)
cur.executemany(
"INSERT INTO build_rows VALUES(%s,%s)",
[(i, 0) for i in range(n + 1, n + 33)],
)
cur.execute("ANALYZE TABLE probe_rows")
cur.execute("ANALYZE TABLE build_rows")
cur.execute("SELECT COUNT(*),SUM(id),SUM(v) FROM probe_rows")
count, id_sum, v_sum = cur.fetchone()
assert count == n and int(id_sum) == n * (n + 1) // 2 and int(v_sum) == 0
cur.execute("SELECT COUNT(*),SUM(id),SUM(v) FROM build_rows")
count, id_sum, v_sum = cur.fetchone()
assert count == 32 and int(id_sum) == sum(range(n + 1, n + 33)) and int(v_sum) == 0
conn.close()Every a.id is at most N and every b.id is greater than N; all v values are zero. Therefore both target predicates are true for all 32*N pairs, while the condition still follows the generic LoopJoin path.
2. Run the target and exact Product control
Target:
SELECT COUNT(*),SUM(a.id),SUM(a.v+b.v),SUM(LENGTH(a.p0)),SUM(LENGTH(a.p1)),
SUM(LENGTH(a.p2)),SUM(LENGTH(a.p3)),SUM(LENGTH(a.p4)),SUM(LENGTH(a.p5)),
SUM(LENGTH(a.p6)),SUM(LENGTH(a.p7)),SUM(b.id)
FROM probe_rows a
JOIN build_rows b ON a.id < b.id AND a.v+b.v >= 0;Exact control for this fixture:
SELECT COUNT(*),SUM(a.id),SUM(a.v+b.v),SUM(LENGTH(a.p0)),SUM(LENGTH(a.p1)),
SUM(LENGTH(a.p2)),SUM(LENGTH(a.p3)),SUM(LENGTH(a.p4)),SUM(LENGTH(a.p5)),
SUM(LENGTH(a.p6)),SUM(LENGTH(a.p7)),SUM(b.id)
FROM probe_rows a CROSS JOIN build_rows b;Both return one identical row with:
COUNT(*) = 32*NSUM(a.id) = 32*N*(N+1)/2SUM(a.v+b.v) = 0- each payload-length sum
= 32*N*256 SUM(b.id) = N*SUM(N+1..N+32)
Normalize all values with str, hash compact JSON, and require the same exact row and hash for every one of the 20 executions per arm. Expected values and hashes are listed above.
Run EXPLAIN <query> and EXPLAIN PHYPLAN ANALYZE <query> for both arms. Require:
- Target
loop joinand controlproduct. - N-row
probe_rowsscan and 32-rowbuild_rowsscan in both arms. - Exactly 32N join output rows and a final aggregate consuming 32N rows and emitting one row.
3. Repeat under CPU profiling
Run arms serially, 20 statements per arm. While one arm is running, capture:
curl --fail --silent --show-error \
'http://127.0.0.1:16011/debug/pprof/profile?seconds=20' \
--output n2-target-n8192.cpu.pprofSave the Product profile separately and repeat the complete procedure at N=16,384. Point go tool pprof at the exact mo-service binary:
go tool pprof -top -nodecount=240 ./mo-service n2-target-n8192.cpu.pprof
go tool pprof -peek='evalConditionWindow|SetJoinBatchValues|PairCondition' \
./mo-service n2-target-n8192.cpu.pprof
go tool pprof -list='loopjoin\.\(\*container\)\.evalConditionWindow' \
./mo-service n2-target-n8192.cpu.pprof
go tool pprof -list='colexec\.SetJoinBatchValues' \
./mo-service n2-target-n8192.cpu.pprof
# Run the same commands on the Product control and at N=16384.The decisive evidence is direct attribution at the staging call and the per-vector const-set call, together with the exact structural plans. Do not infer the finding from elapsed time.
Additional information
At this commit:
evalConditionWindow, lines 178-234 takes the generic path whenPairConditionis nil and callsSetJoinBatchValuesat lines 217-218 before evaluating the condition.SetJoinBatchValues, lines 2432-2440 loops over everybat.Vecsentry and calls the corresponding const-set function at line 2435.
Evidence includes probe_day6_perf_n2.py and complete plans/profiles/receipts under qa294cm_n2_r1_n8192/ and qa294cm_n2_r2_n16384/.
Fresh open+closed searches for SetJoinBatchValues loop join, LoopJoin condition wide columns performance, and evalConditionWindow SetJoinBatchValues returned no matching issue.
Activity