Skip to content

[Bug]: shuffle HashBuild reports no spill above join_spill_mem threshold #26924

Closed as not planned

Description

@Ariznawlll

Description

An eligible shuffle HashBuild remains resident, or at least reports no physical
spill, after join_spill_mem is set to 8,000,000 bytes. EXPLAIN ANALYZE
selects shuffle: range(...), the Join reports 105-139 MiB of memory, and the
queries return correct results, but none of the three targeted plans contains
SpillRows or SpillSize.

This is different from #26556: the planner does select the eligible range
shuffle for both equality-predicate orders. It is also different from #26586:
the query does not fail during spill recovery and returns no budget error.

Environment

  • Branch: main
  • MatrixOne commit: b992c9ef36514e3d1c14760a5311eace122cce94
  • Test harness commit: 3933e729e415ec1e679301b3d8566abdd3146248
  • Date: 2026-08-10
  • Deployment: isolated TKE cluster, 1 DN, 3 LogService, 3 CN and 2 Proxy
  • CN: 14 CPU / 55 GiB per replica
  • Session settings: max_dop=8, join_spill_mem=8000000

Steps to reproduce

Using a source table containing at least 2,000,000 sequential integer rows:

CREATE TABLE spill_probe_2m AS
SELECT id AS k1, MOD(id, 97) AS k2, id AS payload
FROM source_100m WHERE id <= 2000000;

CREATE TABLE spill_build_2m AS
SELECT id AS k1, MOD(id, 97) AS k2, id AS payload
FROM source_100m WHERE id <= 2000000;

SET @@max_dop = 8;
SET @@join_spill_mem = 8000000;

EXPLAIN ANALYZE
SELECT COUNT(*), SUM(p.payload), SUM(b.payload)
FROM spill_probe_2m p
JOIN spill_build_2m b
  ON p.k1 = b.k1 AND p.k2 = b.k2;

EXPLAIN ANALYZE
SELECT COUNT(*), SUM(p.payload), SUM(b.payload)
FROM spill_probe_2m p
JOIN spill_build_2m b
  ON p.k2 = b.k2 AND p.k1 = b.k1;

A third variant used a 2,000,000-row build side with a 128-byte padding column:

CREATE TABLE spill_wide_build_2m AS
SELECT id AS k, CONCAT(CAST(id AS CHAR), REPEAT('x', 128)) AS pad
FROM source_100m WHERE id <= 2000000;

EXPLAIN ANALYZE
SELECT COUNT(*), SUM(p.payload), SUM(LENGTH(b.pad))
FROM spill_probe_wide_2m p
JOIN spill_wide_build_2m b ON p.k = b.k;

Actual behavior

Both multi-key predicate orders choose the expected range shuffle, but neither
plan reports spill:

Join MemorySize=138.45 MiB (min=16.00 MiB, max=16.00 MiB)
Join Cond: (b.k1 = p.k1), (b.k2 = p.k2) shuffle: range(b.k1)
no SpillRows / SpillSize

Join MemorySize=138.71 MiB (min=16.00 MiB, max=16.00 MiB)
Join Cond: (b.k2 = p.k2), (b.k1 = p.k1) shuffle: range(b.k1)
no SpillRows / SpillSize

The wide-build variant behaves the same way:

Join MemorySize=105.13 MiB (min=8.00 MiB, max=38.24 MiB)
Join Cond: (b.k = p.k) shuffle: range(b.k)
no SpillRows / SpillSize

All queries still return the exact expected results. For the multi-key cases:

joined_rows=2000000
probe_sum=2000001000000
build_sum=2000001000000

The post-query health control SELECT 1 succeeds. No panic, OOM or CN restart
was observed.

Expected behavior

For a shuffle HashBuild whose retained/build memory crosses the configured
8,000,000-byte threshold, MatrixOne should enter the supported spill path and
EXPLAIN ANALYZE should expose positive SpillRows/SpillSize measurements.

If the displayed Join memory is not the memory governed by
join_spill_mem, the plan or diagnostics should expose the resolved threshold,
unit and spill-eligibility decision so that the setting has an observable and
testable contract.

Stability and controls

  • Independent workflow reproduction: 1/1.
  • Within that run: 3/3 targeted shuffle plans had no positive spill metric
    (two predicate orders and one wide-build shape).
  • Resident control with join_spill_mem=0: passed with the same exact result.
  • Low-memory query results: passed and matched the resident result.
  • Health/cleanup: SELECT 1 passed; cluster remained healthy and the isolated
    namespace was removed successfully.

Evidence

The three failures are explicit plan assertions for
regex:SpillRows=[1-9][0-9]*; the accompanying shuffle: range assertions pass.

Code analysis

The failing evidence establishes that planner shuffle selection is present and
that SQL correctness is preserved. It does not yet distinguish between:

  1. the resolved join_spill_mem threshold not reaching the executing
    HashBuild workers;
  2. the threshold being interpreted per worker or in a different unit than the
    session-visible value;
  3. physical spill occurring but its SpillRows/SpillSize counters not being
    propagated to EXPLAIN ANALYZE.

These are hypotheses requiring engine-side tracing; this report does not infer
one of them as the confirmed root cause.

Regression coverage

PR matrixorigin/mo-nightly-regression#1329 contains the big-data regression.
After the product/observability contract is confirmed, retain both predicate
orders, the wide build side, resident-vs-spill result equality, positive spill
evidence and the post-recovery health check.

Related

Activity

  1. added this to the MO-202608 milestone on Aug 10, 2026
  2. added theissue type on Aug 10, 2026
  3. added
    kind/bug
    on Aug 10, 2026
  4. aptend commented on Aug 10, 2026

    @aptend
    Contributor

    I reproduced this locally at the reported MatrixOne commit (b992c9ef36514e3d1c14760a5311eace122cce94) with an embedded 3-CN cluster, 2,000,000 sequential rows, max_dop=8, and temporary per-operator instrumentation.

    Confirmed behavior

    For the balanced multi-key shuffle join, all 8 HashBuild workers received the configured value unchanged:

    raw_threshold=8000000 resolved_threshold=8000000
    rows_per_worker ~= 250000
    predicted/retained_before_map ~= 6000000 bytes
    threshold_crossed=false
    hashmap_size=16777400 bytes
    retained_plus_hashmap ~= 22777376 bytes per worker
    physical_spill=false
    

    Therefore, no physical spill occurred and the missing SpillRows/SpillSize values are not a propagation problem.

    join_spill_mem=8000000 is interpreted as bytes (>100000 selects byte mode) and is applied independently by each eligible shuffle HashBuild worker. The early decision checks retained build batches plus the current input batch. With DOP 8, each worker retains only about 6 MB, so it does not cross the 8 MB threshold.

    The roughly 16 MiB HashMap is allocated afterward. In this two-BIGINT-key case MatrixOne uses StringHashMap: 250k distinct keys require 524,288 slots at the 50% load limit, and each slot is 32 bytes, giving 16,777,216 bytes plus small descriptors. A successful HashMap build is not followed by another join_spill_mem check. The separate HashBuild hard allocation budget does account for both retained batches and the HashMap (roughly 22.78 MiB per worker here); it was large enough, so its admission-failure spill fallback was not activated.

    Why EXPLAIN reports 128-138 MiB

    Join MemorySize is not the memory value tested by join_spill_mem. It sums MemorySize from all physical operators mapped to the logical Join node, and those operators do not all use the field with identical semantics.

    The local Join MemorySize=128.74 MiB decomposed exactly as:

    8 HashJoin operators * 16,777,400 bytes = 128.001 MiB
    2 Shuffle pool peaks                      =   0.739 MiB
    --------------------------------------------------------
    logical Join MemorySize                   = 128.740 MiB
    

    This aggregation mechanism also explains the reported 138.45 MiB: approximately 128 MiB is the eight JoinMap/HashMap observations, while the remainder comes from other physical operator statistics mapped to the Join node. The current EXPLAIN line does not retain enough per-operator detail to reconstruct that remainder exactly. Its min/max=16 MiB also describes physical operator statistics, not the per-worker pre-map spill-decision value.

    The wide-table variant is not evidence that 128-byte pad was retained by HashBuild. In the local reproduction the optimizer built the narrow p(k,payload) side: each worker retained about 4 MB, then allocated an approximately 8 MiB IntHashMap, and again did not cross the pre-map 8 MB threshold.

    Controls

    DOP=8, join_spill_mem=8,000,000 bytes: spill starts = 0
    DOP=8, join_spill_mem=2,000,000 bytes: spill starts = 8
    DOP=8, join_spill_mem=100,000 rows:     spill starts = 8
    DOP=1, join_spill_mem=8,000,000 bytes: spill starts = 1
    

    Skewing the range distribution so that only 3 workers received large partitions also produced 3 spill starts, confirming that the decision is per active worker/partition.

    Conclusion

    The setting reaches the executing workers and works according to the current implementation. The reported plans genuinely do not spill because their per-worker retained batch memory is below 8 MB before HashMap construction. Comparing the aggregated EXPLAIN Join MemorySize with join_spill_mem is therefore not a valid spill oracle.

    There is still a real contract/observability gap: the setting looks like a final HashBuild resident-memory limit, but currently acts as a pre-HashMap retained-batch threshold; HashMap construction can raise resident memory above it without a post-build recheck. EXPLAIN also does not expose the resolved threshold, unit/mode, actual build side, per-worker decision value, or spill decision. If join_spill_mem is intended to cap final resident HashBuild memory, the implementation needs a post-map admission/recheck policy; otherwise the regression assertions and user-facing diagnostics should be adjusted to the narrower current contract.

  5. assigned and unassigned on Aug 11, 2026
  6. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    This report is now tracked together with #30125. The canonical issue retains explicit acceptance cases for the behavior described here. This is an administrative duplicate/consolidation closure only; the underlying defect is not claimed fixed. The original description and discussion remain available on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions