Skip to content

fix(sql): preserve join locality and numeric CAST metadata - #29452

Merged
XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
ck89119:issue-7559-main
Sep 29, 2026
Merged

XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
ck89119:issue-7559-main

Conversation

@ck89119

@ck89119 ck89119 commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #7559 — prerequisites only; this PR does not implement general multilevel decorrelation or close the issue.

What this PR does / why we need it:

Fix three independently reproducible failures found while designing multilevel correlation support:

  1. Wrong results across CNs: a coordinator-side window probe joined to a remote build could receive a cleanup-generated empty JoinMap, turning matching LEFT JOIN rows into NULL extensions. Establish batch-transfer boundaries before constructing process-local build/probe state.
  2. Unencodable WINDOW: a subsequent JOIN could move a local window subtree into remote serialization. Keep that JOIN stage local and disable only its shuffle; scans remain remote.
  3. Invalid numeric CAST metadata: string-domain inference could manufacture a numeric-typed string witness. Stop propagation when the CAST result has no string domain, retaining existing literal validation and string/binary behavior.

Preserve safe colocated/broadcast placements and the existing owner-aware shuffle path. Cover ASOF build-left's physical side swap. No new wire fields, materialization admission, or HashBuild empty-map semantics.

Regression evidence

The same ordinary SQL test fails against the unpatched production-entry overlay with, respectively, incorrect NULL rows, 20101: unexpected operator: Window, and 20301: string literal form requires a string literal and string type.

The fix adds typed-plan tests, an isolated two-CN SQL package (including remote placement, NULLs, duplicates, LIMIT and empty input), and a public BVT with prepared-statement reuse. The separate test process is required by embedded-cluster admission; it does not destroy the shared single-CN fixture.

Design and boundaries: physical prerequisites r1.

Validation

Validated after merging mo/main at d99187d7b3 and applying the local-parallelism review fix, using Go/gofmt 1.26.4 and the repository CGo wrapper:

  • Full pkg/sql/compile and pkg/sql/plan tests.
  • Full pkg/tests/sqlintegration and pkg/tests/sqlintegration/multicn tests.
  • Full compile-package -race; exact two-CN -race measurement and budget-derived -count=1 repeat.
  • Incremental golangci-lint: 0 issues; make build passed.
  • Changed production coverage: 29/29 statements (100%) in Go coverage blocks intersecting changed lines; above the 75% gate.
  • mo-tester generated results, independently checked expected rows, and two normal comparison runs on the final binary: 19/19 each, schema removed after each run. Task-owned service/data cleaned up.

General dependency ownership/substitution, demand-aware scalar evaluation, parameter-domain types, source admission and lowering budgets remain separate design gates for the rest of #7559.

@aunjgr aunjgr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 68a781a. The join-placement change resolves process-local build/probe dependencies before force-one-CN reshaping, keeps WINDOW stages local while preserving remote scans, and handles ASOF side reversal. The CAST-domain guard matches the result type. Focused plan, two-CN, and public SQL regressions cover wrong rows, remote WINDOW encoding, and metadata failure; CI is green. No blocker found.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep review of exact head 68a781a against base/merge-base d8152cb: APPROVE. No verified blocker after reading all nine changed files, the design boundary, existing placement/merge/build consumers, tests and prior review history. No subagents or product edits. There are no outstanding inline comment threads; the two substantive prior reviews agree with the current source.

Design/ownership: these are bounded repairs of valid SQL, not delivery of general multilevel decorrelation (#7559 remains open). JoinMap remains owned by the process-local build/probe path. The fix transports batches through the existing Merge/Connector owner before installing build state, rather than inventing map transport or changing empty-build semantics. WINDOW remains on the coordinator because its remote encoding is unavailable. The force-one-CN decision is shared before and during probe construction, so FULL/RIGHT/DEDUP build placement follows the final probe owner; ASOF build-left passes the physically swapped sides. Existing safe broadcast and owner-aware shuffle paths remain in use.

Adjacent challenges: same remote CN versus different remote CN; already-local parallel/SINK probes versus local pinned dependency plus remote input; forced multi-probe FULL/RIGHT/DEDUP versus ordinary INNER; WINDOW on either side and nested scopes; numeric CAST versus VARCHAR/VARBINARY provenance. Typed-scope tests assert owner/operator identity and preserve remote scan addresses. The public SQL fixture checks full duplicate/NULL/unmatched results, LIMIT early completion, empty input and real remote placement; BVT adds prepared reuse. The design correctly distinguishes SQL semantic controls from the typed-scope red/green case that actually selects multiple probe scopes.

Unhappy/resource closure: new merge scopes own their original inputs as PreScopes; release recursively owns operators/scopes. Existing bounded PipelineEdges and context-aware Connector sends are retained; MergeRun cancels siblings on start/runtime failure before joining them, and pipeline Reset/abort remains the terminal owner. The added topology has input-to-merge edges, not a new back edge or detached producer. No new wire/catalog/state-machine/cancellation protocol is introduced.

Performance/engineering quality: locality is a correctness-first choice, not a claimed speedup. Coordinator work can increase for the previously invalid placements, but all-local parallelism, safe same-remote placement, remote scans and ordinary shuffle are explicitly preserved. The implementation increment (+106/-11), tests/BVT (+500) and design (+59) have distinct purposes: lightweight topology proofs, one necessary isolated two-CN fixture, and public SQL behavior. No demand for a generic placement abstraction or broader decorrelation machinery.

Evidence reused: relevant author full compile/plan and both integration-package results, compile/two-CN race evidence and two normal BVT comparisons (19/19 each with teardown); prior targeted validation at 1d5e113 remains semantically relevant after the final unrelated fulltext/docs merge. Exact-head CI Required is successful. I independently checked the current source closures and git diff --check; no fresh local execution or performance benchmark is claimed.

@mergify mergify Bot added the queued label Sep 29, 2026
@mergify

mergify Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-29 10:53 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-29 11:01 UTC · at a616ccb18ada02405a67c02d42820bbf9f1a190c

This pull request spent 8 minutes 13 seconds in the queue, with no time running CI.

Reason

Pull request #29452 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit a97f9c9 into matrixorigin:main Sep 29, 2026
20 of 21 checks passed
@mergify mergify Bot added dequeued and removed queued labels Sep 29, 2026
@ck89119
ck89119 deleted the issue-7559-main branch September 29, 2026 14:09
mergify Bot pushed a commit that referenced this pull request Nov 25, 2026
…tes (4.2-dev) (#33155)

## What type of PR is this?

- [x] BUG
- [x] Test and CI

## Which issue(s) this PR fixes:

Fixes #33150. Branch-adapted backport of the applicable execution-placement fixes from #29452 (main merge `a97f9c940bba`).

## What this PR does / why we need it:

A `SINK_SCAN` reads a process-local producer register; a hash join consumes a process-local JoinMap. Nesting these under a sole remote probe does not transport those dependencies. On a synchronous indexed UPDATE the remote hash build can end up waiting on a register for which no producer was shipped. Increasing a timeout does not create that producer.

Keep the owner of local-only operators; when the inputs cross the ownership boundary, transfer batches through the normal merge/connector before constructing the JOIN. A remotely eligible scan can remain remote. No timeout, JoinMap cleanup behavior, index format or transaction semantics are changed.

When the coordinator is one of several probe CNs, it can host either a SINK_SCAN or a WINDOW build. It broadcasts the resulting batches through the existing receivers, and each peer probes with its own HashBuild and JoinMap. A topology without a coordinator host, a forced-single join, and a shuffle involving WINDOW retain their coordinator fallback.

### Backport boundary

The numeric-CAST string-domain inference and physical ASOF build-left entry points from the upstream change do not exist on this branch. Do not introduce those main-only features to backport their guards.

The updated 4.2 base includes #33169, the backport of the singleton reader fix from #27796 for #27755. With the JOIN placement fix **alone**, a one-remote-worker UPDATE could commit the new base row and full-text postings but leave **zero** IVF entries for that PK. The physical index failure was independently observed from both CNs after a writer-commit fence. The write uses the current IVF version and centroids; when those source rows were still in memory a singleton remote block reader silently skipped them. Flushing just those sources changed this control from FAIL to PASS. This is why the companion reader fix is needed here; flushing production tables is **not** the fix.

The singleton remote worker now uses the relation it opened at the statement snapshot to read the complete input. Distributed remote workers retain the persisted-block reader and its original partitioning. The branch's account context, membership filters and cancellation path are preserved.

### Validation

- Compiler/wire control: old 4.2-dev fails the three misplaced-owner cases; local parallelism and legal remote transport are controls, not things to disable. Check forced single-probe and WINDOW placement as well as empty input and cancellation.
- Public SQL: an isolated two-CN MO cluster, one eligible peer, `query_max_workers=1`, synchronous full-text + IVFFLAT indexes. Check the actual peer for the windowed reads, selected remote worker and index operations for UPDATE, and the ordinary control on the coordinator. Exercise zero matches, ROLLBACK, then COMMIT. Fence both observers at the writer commit timestamp and independently check base text/vector, physical IVF entry count and stored vector, and old/new full-text postings.
- Negative/positive controls: the base remote indexed UPDATE times out on empty input; JOIN-only returns, but the committed PK has 0 matching physical IVF rows on both observers. Flushing just the metadata and centroids hides the reader defect. The committed regression instead deliberately leaves these two tables **unflushed**. A separate one-row table also checks the same remote SELECT before and after its own flush.
- **Review regression:** With the exact d227e96 production files and the final regression tests, the coordinator-first, coordinator-last, and mixed-source build cases all lost the peer join (1 probe stage instead of 2). All three pass on 69e6e21. The tests round-trip the peer pipeline, verify its HashJoin and colocated HashBuild, matching JoinMap tag and remote receiver UUID/address, and verify the original producer register. No-host and forced-single controls still gather safely.
- **Standalone (69e6e21, Linux/amd64, Go 1.26.4):** full compiler package passed (34.408s); four focused compiler controls including all 11 placement cases passed five repetitions with `-race -short -tags matrixone_test`; scoped `go vet` passed. Isolated two-CN SQL fixture passed (16.68s). The peer read row 42 before and after flush. Both observers saw IVF total/exact `1/1`, and old/new full-text postings `1/0` after rollback and `0/1` after commit, with the correct base text and vector.
- **Combined integration, not a PR dependency merge:** locally merged exactly 69e6e21 and #33153 at e746fb5 with no conflicts. The IVF replay/wire, JOIN placement, singleton reader and writable-workspace placement regressions passed together; the isolated two-CN public SQL fixture passed again (16.66s). That validation used the explicit-transaction scheduling guard from #33153. The current PR also carries that same scheduling commit, independently of the IVF changes.

These results establish correctness and plan placement, not a production throughput benchmark. The local race result above is targeted, not a full compiler race result.



### Follow-up to review 6043625892

The writable workspace belongs to the ingress CN. AP statements after a write now require that owner to be eligible and included in the selected worker set. With a one-worker cap the owner executes the scan. When the owner is draining or excluded by placement, the statement returns an explicit scheduling error. Read-only transactions can still use a sole remote worker. The shared scheduling change comes from commit `fa605a7846` of #33153.

On the reviewed head `69e6e2109b`, an ordinary unflushed table contained committed key 42. A transaction deleted 42, inserted 43, and a remote SELECT succeeded with key 42. On the revised head, the draining ingress rejects that query with `current-cn-draining`. The eligible owner returns just key 43. In the WINDOW regression, the reviewed head collapsed three valid two-probe broadcasts to one stage. The revised head retains both JOINs with the coordinator listed first, last, or with a mixed build. The tests also check the coordinator WINDOW, the decoded peer HashJoin/HashBuild and its dispatch registration, and the no-host, forced-single and shuffle cases.

Tested revision: `bd998a2ed0` against 4.2 base `bb197e5118`. The complete compiler, scheduler, and isolated two-CN SQL packages passed. The SQL fixture also checked FULLTEXT postings and physical IVF entries after both rollback and commit.

- A separate public SQL comparison used two Working CNs and 131,072 probe rows. Both revisions returned 131,072 rows and a sum of 327,680. The executed plan on `69e6e2109b` had the WINDOW and hash join on the coordinator and no hash join or hash build on the peer. On `bd998a2ed0` the WINDOW stayed on the coordinator, and both CNs had their own hash join and hash build. This checks operator placement; no throughput comparison was made.
- A three-CN SQL fixture with 8,600,005 rows exercised read-your-writes and downstream materialization. A Working owner with a cap of one or two workers returned the replacement key and all three observers read the correct committed summary. A draining owner received an explicit error on both SELECT and INSERT … SELECT and wrote no summary. Prepared SELECTs passed for both owner states. The first run timed out at a preliminary EXPLAIN ANALYZE scheduling check in the two prepared cases, before executing them. Their successful rerun used EXPLAIN VERBOSE for that preliminary check and executed the prepared queries and materializations against the full dataset.
- The JOIN placement, compiler workspace, and worker-selection regressions passed three repetitions with `-race -short -tags matrixone_test`. Scoped `go vet` passed and incremental lint reported zero issues.


Approved-by: XuPeng-SH <[email protected]>

This branch was previously deployed

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

Labels

kind/bug Something isn't working kind/documentation Improvements or additions to documentation kind/test-ci size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants