[Bug]: Wide INSERT … SELECT requests a near-2 GiB JOIN output allocation despite a working batched path

Open
#33,254 0 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@LeftHandCold is already working on this.

Since Nov 26, 2026.

  • #33303 by @LeftHandCold — open

Assessment

This issue has not been assessed yet.

Description

kind/bug severity/s0

Customer impact

A single wide INSERT … SELECT over two broadcast LEFT JOINs can fail with MySQL error 3015. The same logical result can be committed in one transaction when the input is partitioned into smaller disjoint ranges. This is a non-blocking follow-up to #33242. The stable base d2bc81d9f0, the backport head 8353ba7fac, and upstream main 336486e108 all rejected the single statement. #33246 tracks the separate key-only HashBuild and probe-reset cases.

Reproduction on an isolated single CN

The observed configuration used DOP 1, a 7 GiB process cgroup, an 8 GiB frontend query configuration, the default single-allocation limit (2,147,483,631 bytes), and an effective allocation account of 3 GiB. The effective account matters when comparing results across hosts.

Run in a fresh database. The four long source values each have 262,150 bytes.

SET @@max_dop = 1;
SET SESSION optimizer_hints='forceOneCN=1,joinOrdering=1';
CREATE TABLE p (id INT, k INT, v MEDIUMTEXT);
CREATE TABLE b (id INT, k INT);
CREATE TABLE e (id INT);
CREATE TABLE sink (pid INT, bid INT, eid INT, v MEDIUMTEXT);

INSERT INTO p
SELECT result, CASE WHEN result <= 4 THEN result ELSE result + 10000 END,
       CASE WHEN result <= 4 THEN CONCAT(
           REPEAT(CHAR(64 + result), 52430), REPEAT(CHAR(64 + result), 52430),
           REPEAT(CHAR(64 + result), 52430), REPEAT(CHAR(64 + result), 52430),
           REPEAT(CHAR(64 + result), 52430))
       ELSE NULL END
FROM generate_series(1,10000) g;
INSERT INTO b SELECT result, result % 4 + 1 FROM generate_series(1,8192) g;
INSERT INTO e VALUES (1),(8192),(NULL);

INSERT INTO sink
SELECT q.pid, q.bid, e.id, q.v
FROM (SELECT p.id AS pid, b.id AS bid, p.v AS v
      FROM p LEFT JOIN b ON p.k = b.k LIMIT 30000) q
LEFT JOIN e ON q.bid = e.id;
SELECT COUNT(*) FROM sink;

The expected result has 18,188 rows. In the failing runs the client received 3015 and the target remained empty. On main and the backport head, a diagnostic replay recorded 1,745,941,624 bytes already charged and a 2,147,483,631-byte request for JOIN output against an account limit of 3,221,225,472 bytes. The allocator correctly rejected the request. The improvement to evaluate is whether the JOIN can emit a smaller batch before requesting that much additional capacity.

Controls and related storage observation

  • With 6,200-byte source values, the single statement succeeded on both branches. The client checked all 8,192 matches, 9,996 outer rows, NULLs and text values.
  • At full width, five statements in one explicit transaction succeeded on both branches. Each kept the same query and applied a disjoint p.id predicate inside the derived table before its LIMIT. The ranges were 1, 2, 3, 4 and 5–10000. A second connection observed zero rows before commit, then all 18,188 afterwards. The full result matched byte for byte. The LIMIT exceeds the total result in this fixture.
  • In a separate test with the single-allocation limit reduced to about 35 MiB, copying the 6,200-byte result from an ordinary source table using INSERT INTO sink_copy SELECT * FROM sink also failed. Both branches reached Sinker.Write during commit. Main returned 1105 and the stable candidate returned 20101. Both targets remained empty. This lower-limit storage observation has a distinct failure site. Its incidence at the default production limit is unverified.

Acceptance

Keep the memory limits and transaction atomicity intact. Evaluate smaller output batches for the single-statement case and validate with the same effective account, full row and payload checks, and a narrow-row performance control. Track the storage observation separately within this investigation.

Dominant language
Go
Stars
1.9k
Forks
312
Avg merge
22h 59m
Merged PRs (30d)
736

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from matrixorigin/matrixone

All issues in matrixorigin/matrixone

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.