Repository navigation
fix(compile): preserve in-memory rows on single remote scans - #27796
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
aptend
left a comment
There was a problem hiding this comment.
Deep-reviewed exact head 721bea4 against the linked intermittent multi-CN DML failure and the complete diff.
The ownership split is consistent: a single remote CN owns the complete scan and now retains/reopens the executing-CN relation so its relation reader receives the in-memory block sentinel; distributed remote scopes remain on block readers so the local scope retains in-memory-row ownership. I also checked encode/decode behavior, exact-CN relation acquisition, tenant/system-account and fulltext-filter propagation, and reader cleanup/error paths. The change adds no new goroutine, wait dependency, or unbounded retained state.
Local validation on the exact head passed:
- go test ./pkg/sql/compile ./pkg/tests/dml -count=1
- focused race tests for owner selection, decoded single-remote scopes, and the reported DML regression, count=3
- TestForcedMultiCNDeleteAndInsertIgnore, count=20
- go vet ./pkg/sql/compile ./pkg/tests/dml
- git diff --check
No blocking issue found.
Merge Queue Status
This pull request spent 39 minutes 18 seconds in the queue, with no time running CI. Waiting for
All conditions
ReasonPull request #27796 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.
Failing checks:
HintYou 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. Tick the box to put this pull request back in the merge queue (same as
|
…rigin#27796) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#27755 ## What this PR does / why we need it: A scan assigned to exactly one remote CN collects all relation data, including the memory-block sentinel for committed rows still held in that CN's partition state. The remote execution path previously always used block readers, which deliberately strip that sentinel for distributed scans, so a single remote scan could intermittently return an empty result before the rows were flushed into persisted objects. This PR: - uses the executing CN's relation reader when one remote CN owns the complete scan; - keeps block readers for distributed remote scopes so only the local scope owns in-memory rows; - preserves tenant/system account context and fulltext membership-filter metadata on the relation-reader path; - adds deterministic unit coverage for local, single-remote, and distributed-remote reader ownership. Validation: - focused compile tests and race tests; - full `pkg/sql/compile` and `pkg/tests/dml` package tests; - `TestForcedMultiCNDeleteAndInsertIgnore` with `-count=20` and under `-race`; - `go vet ./pkg/sql/compile ./pkg/tests/dml`. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…rigin#27796) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#27755 ## What this PR does / why we need it: A scan assigned to exactly one remote CN collects all relation data, including the memory-block sentinel for committed rows still held in that CN's partition state. The remote execution path previously always used block readers, which deliberately strip that sentinel for distributed scans, so a single remote scan could intermittently return an empty result before the rows were flushed into persisted objects. This PR: - uses the executing CN's relation reader when one remote CN owns the complete scan; - keeps block readers for distributed remote scopes so only the local scope owns in-memory rows; - preserves tenant/system account context and fulltext membership-filter metadata on the relation-reader path; - adds deterministic unit coverage for local, single-remote, and distributed-remote reader ownership. Validation: - focused compile tests and race tests; - full `pkg/sql/compile` and `pkg/tests/dml` package tests; - `TestForcedMultiCNDeleteAndInsertIgnore` with `-count=20` and under `-race`; - `go vet ./pkg/sql/compile ./pkg/tests/dml`. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…rigin#27796) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: issue matrixorigin#27755 ## What this PR does / why we need it: A scan assigned to exactly one remote CN collects all relation data, including the memory-block sentinel for committed rows still held in that CN's partition state. The remote execution path previously always used block readers, which deliberately strip that sentinel for distributed scans, so a single remote scan could intermittently return an empty result before the rows were flushed into persisted objects. This PR: - uses the executing CN's relation reader when one remote CN owns the complete scan; - keeps block readers for distributed remote scopes so only the local scope owns in-memory rows; - preserves tenant/system account context and fulltext membership-filter metadata on the relation-reader path; - adds deterministic unit coverage for local, single-remote, and distributed-remote reader ownership. Validation: - focused compile tests and race tests; - full `pkg/sql/compile` and `pkg/tests/dml` package tests; - `TestForcedMultiCNDeleteAndInsertIgnore` with `-count=20` and under `-race`; - `go vet ./pkg/sql/compile ./pkg/tests/dml`. --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
#33169) ## What type of PR is this? - [x] BUG - [x] Test and CI ## Which issue(s) this PR fixes: Fixes #33168 on `4.2-dev`. ## What this PR does / why we need it: An AP scan assigned entirely to one remote CN can miss a committed insert or count a deleted row. An `INSERT … SELECT` can then commit the wrong aggregate to another table. The sole executing CN already opens the relation and collects its full ranges, including its in-memory data. This change retains that relation handle on the worker and builds the readers at the transaction snapshot with all tombstone checks. Remote workers that share a distributed scan keep using the block reader for their assigned ranges. The single-worker path retains the account context and serialized membership filters used by published and index tables. ## Relationship to earlier changes Main addressed the same reader ownership issue in #27796 for #27755. The two files in this backport match the corresponding files in #33155 at `d227e967f2`. A local three-way merge of the two PR heads on base `9ed1645371` produced exactly the tree of #33155. The JOIN placement changes remain reviewable there. ## Validation - Added focused coverage for local, distributed remote and single remote scans, including decoded remote scopes, the in-memory range marker, cluster and published table identity, and full-text/IVF membership filters. On the unmodified base, the decoded single-worker cases fail because they never call the relation reader. - The complete `pkg/sql/compile` unit suite passed. Focused reader and cancellation tests passed three repetitions under the race detector. Targeted combined-table reader tests, `go vet`, and the repository's incremental lint also passed. - On real local MatrixOne services with three CNs and 8,600,005 generated seed rows, the base missed a committed insert in both a single-remote aggregate and the committed destination table. All three observers confirmed the wrong total after reaching the writer's commit timestamp. A baseline delete probe also counted a deleted key. - On the candidate, the same public SQL with uninstrumented production code returned 8,600,006 after insert and 8,600,005 after delete, both before and after a flush. All three CNs read back the correct committed summaries. - In an independent two-CN snapshot-isolation case, a held snapshot continued to return three rows totaling 83 after a different CN committed changes and after a flush. A fresh snapshot returned four rows totaling 131. The run also checked rolled-back mutations, empty input and the pure `COUNT(*)` path. Test-only plan selection and diagnostic traces confirmed execution on the peer. - After publication we fetched GitHub's PR head and repeated the snapshot suite. All 11 scans executed on the intended peer and passed. Three adjacent SQL regressions (delete/select, remote insert-ignore with conversion, and distributed DISTINCT) passed. Six reader and cancellation tests also passed ten shuffled repetitions. - On published head `453131d68b`, we repeated the large fixture with three Working CNs, worker cap one, and a real label selector with one eligible peer. Diagnostic hooks recorded the reader actually built by each statement. All eight aggregate and materialization scans executed there. All 12 fenced destination reads and all 12 source primary-key checks passed. Repeating that exact labeled configuration against `9ed1645371` selected the block reader for all eight statements. The aggregate and the committed summaries on every CN were wrong in three of the four phases. | State of source | Expected total | Base query and stored summary | PR query and stored summary | | --- | ---: | ---: | ---: | | Insert committed, before flush | 8,600,006 | 8,600,005 | 8,600,006 | | After insert flush | 8,600,006 | 8,600,006 | 8,600,006 | | Delete committed, before flush | 8,600,005 | 8,600,006 | 8,600,005 | | After delete flush | 8,600,005 | 8,600,006 | 8,600,005 | A separate tiny-table test with forced distributed planning hit `unexpected operator: Output` during remote-plan encoding on both the base and the PR. The snapshot tests described above kept the output operator on the coordinator, traced which peer actually read the table, and checked each result. This backport applies to future scans. Previously materialized incorrect summaries need to be recomputed from the source. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…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]>
What type of PR is this?
Which issue(s) this PR fixes:
issue #27755
What this PR does / why we need it:
A scan assigned to exactly one remote CN collects all relation data, including the memory-block sentinel for committed rows still held in that CN's partition state. The remote execution path previously always used block readers, which deliberately strip that sentinel for distributed scans, so a single remote scan could intermittently return an empty result before the rows were flushed into persisted objects.
This PR:
Validation:
pkg/sql/compileandpkg/tests/dmlpackage tests;TestForcedMultiCNDeleteAndInsertIgnorewith-count=20and under-race;go vet ./pkg/sql/compile ./pkg/tests/dml.