Repository navigation
fix(dml): preserve join scope for indexed deletes - #28310
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? |
|
Additional 55 Linux/amd64 black-box validation on the exact PR source (
The service was stopped using an exact executable-path check and the isolated data/logs were removed afterward. |
LeftHandCold
left a comment
There was a problem hiding this comment.
Reviewed head 6c8f7fbe3cd2d4a7b4b9cedb5366c46a80970401 against base/merge-base 4fdb9e91615f9fc37703039ae28a47849206d1d6. No blocking findings in this revision.
The fix closes the root boundary in #28309: absence of WHERE/LIMIT alone does not imply that the target row set is unrestricted. Both JOIN and USING have TableRefs populated by the parser, so the shared predicate now rejects them before either a base-table truncate or an independent hidden-table delete-all shortcut can be selected.
Review coverage:
- Read all six changed files/hunks. R2 behavioral closure: modern/legacy DELETE classification through base-table and regular/IVF/MASTER/FULLTEXT maintenance. The context-field rename is internal; the existing POSTDML/protobuf field and producer/consumer propagation remain compatible. This is a focused bug fix, not a feature/major-refactor design-gate case.
- Checked that ordinary unrestricted DELETE retains its prior classification and that WHERE, LIMIT 0, multi-target, JOIN/USING and explicit partition restrictions cannot enter the new unrestricted branch. Physical restrictions for foreign keys, table metadata, session settings and the modern RETURNING route remain separate.
- Followed the row-producing SELECT/source stream, hidden-index row-scoped branches and POSTDML consumer. The classification change does not introduce an alternative row-selection algorithm; it removes the incorrect delete-all shortcut. Base primary-key locking remains present, and the relevant index lock targets retain the established row-lock path.
- Reviewed the helper/typed-plan UT and the BVT/result pair: empty source with truncate disabled independently checks surviving base rows and FULLTEXT contents; duplicate source matches with truncate enabled checks surviving rows and deleted/surviving search terms. Existing multi-table cases were not weakened.
Scoped unhappy-path check:
| Dimension | Result for this change |
|---|---|
| Q1 ownership | No new resource owner; pooled DML context is reset as a whole, including the renamed boolean. |
| Q2 waits | No new wait/cancel/retry protocol; restricted deletes reuse the existing row-lock/maintenance path. |
| Q3 growth | No new registry, cache or persistent queue; added classification work is constant-size. Existing row-scoped work is necessary to evaluate the requested delete set. |
Evidence: reviewed/reused the author's exact-head Linux/amd64 validation record in the PR description (focused planner UT/race, planner and postdml packages, normal-comparison BVT twice, and FULLTEXT/MASTER public-path controls). Independently checked the complete committed diff, parser/consumer closure and git diff --check (pass). I did not rerun a service, heavy UT or BVT locally. Public CI was still partially in progress when checked; this approval is the code-review conclusion, not a claim that all CI has completed.
## What type of PR is this? - [x] Bug ## What this PR does / why we need it Irregular indexes currently route `DELETE` through the legacy DML planner. That planner classified every single-target statement without `WHERE`/`LIMIT` as an unrestricted whole-table delete, even when `TableRefs` contained a JOIN or USING source. The resulting plan could truncate the base table or independently delete every hidden-index row without evaluating the join. This change establishes one shared semantic predicate for an unrestricted delete: exactly one target, no WHERE, no LIMIT, no additional table references, and no partition restriction. Both modern truncate rewriting and the legacy fallback use that predicate. Physical truncate eligibility remains a separate decision for RETURNING, foreign keys, partitions, session settings, and other table metadata. The internal flag is renamed to `isUnrestrictedDelete` so all base-table, regular-index, IVF, MASTER, FULLTEXT, and POSTDML consumers express the actual contract. Closes matrixorigin#28309. ## Test plan ### Automated - Planner UT covers plain DELETE, ORDER BY-only, WHERE, LIMIT 0, JOIN, USING, partition restriction, multiple targets, and nil input. - Planner shape UT forces the synchronous FULLTEXT legacy fallback and asserts the origin DELETE cannot truncate and row-scoped hidden-index maintenance is retained. - Distributed SQL regression covers: - empty JOIN with `delete_opt_to_truncate=0`, verifying both base rows and FULLTEXT contents survive; - duplicate matches with truncate enabled, verifying one target row is deleted once and surviving/deleted FULLTEXT terms agree with the base table. ### Validation Linux/amd64 on 10.222.1.55, base `4fdb9e91615f9fc37703039ae28a47849206d1d6`, head `6c8f7fbe3c`: - `make clean && make -j12` - focused planner UT: pass - focused planner UT with `-race`: pass - `./pkg/sql/plan` and `./pkg/sql/colexec/postdml`: pass - `delete_multiple_table.sql` through mo-tester normal comparison mode twice on the same instance: 128 pass, 0 fail, 2 pre-existing ignored (100%); 1.283s and 1.487s - black-box FULLTEXT matrix: empty source, ON false, CROSS/RIGHT/LEFT JOIN, NULL key, derived empty source, USING, WHERE TRUE control, prepared-statement reuse, and duplicate matches: pass - black-box MASTER hidden-table counts: empty JOIN 6 -> 6; partial duplicate match 6 -> 4 while base rows 3 -> 2 - full repository `golangci-lint` 2.6.2: 0 issues - license header check: 5106 checked, 0 invalid - `git diff --check` and gofmt: pass The 55 test service and isolated data were removed after validation.
## What type of PR is this? - [x] Bug ## What this PR does / why we need it Irregular indexes currently route `DELETE` through the legacy DML planner. That planner classified every single-target statement without `WHERE`/`LIMIT` as an unrestricted whole-table delete, even when `TableRefs` contained a JOIN or USING source. The resulting plan could truncate the base table or independently delete every hidden-index row without evaluating the join. This change establishes one shared semantic predicate for an unrestricted delete: exactly one target, no WHERE, no LIMIT, no additional table references, and no partition restriction. Both modern truncate rewriting and the legacy fallback use that predicate. Physical truncate eligibility remains a separate decision for RETURNING, foreign keys, partitions, session settings, and other table metadata. The internal flag is renamed to `isUnrestrictedDelete` so all base-table, regular-index, IVF, MASTER, FULLTEXT, and POSTDML consumers express the actual contract. Closes matrixorigin#28309. ## Test plan ### Automated - Planner UT covers plain DELETE, ORDER BY-only, WHERE, LIMIT 0, JOIN, USING, partition restriction, multiple targets, and nil input. - Planner shape UT forces the synchronous FULLTEXT legacy fallback and asserts the origin DELETE cannot truncate and row-scoped hidden-index maintenance is retained. - Distributed SQL regression covers: - empty JOIN with `delete_opt_to_truncate=0`, verifying both base rows and FULLTEXT contents survive; - duplicate matches with truncate enabled, verifying one target row is deleted once and surviving/deleted FULLTEXT terms agree with the base table. ### Validation Linux/amd64 on 10.222.1.55, base `4fdb9e91615f9fc37703039ae28a47849206d1d6`, head `6c8f7fbe3c`: - `make clean && make -j12` - focused planner UT: pass - focused planner UT with `-race`: pass - `./pkg/sql/plan` and `./pkg/sql/colexec/postdml`: pass - `delete_multiple_table.sql` through mo-tester normal comparison mode twice on the same instance: 128 pass, 0 fail, 2 pre-existing ignored (100%); 1.283s and 1.487s - black-box FULLTEXT matrix: empty source, ON false, CROSS/RIGHT/LEFT JOIN, NULL key, derived empty source, USING, WHERE TRUE control, prepared-statement reuse, and duplicate matches: pass - black-box MASTER hidden-table counts: empty JOIN 6 -> 6; partial duplicate match 6 -> 4 while base rows 3 -> 2 - full repository `golangci-lint` 2.6.2: 0 issues - license header check: 5106 checked, 0 invalid - `git diff --check` and gofmt: pass The 55 test service and isolated data were removed after validation.
## What type of PR is this? - [x] Bug ## What this PR does / why we need it Irregular indexes currently route `DELETE` through the legacy DML planner. That planner classified every single-target statement without `WHERE`/`LIMIT` as an unrestricted whole-table delete, even when `TableRefs` contained a JOIN or USING source. The resulting plan could truncate the base table or independently delete every hidden-index row without evaluating the join. This change establishes one shared semantic predicate for an unrestricted delete: exactly one target, no WHERE, no LIMIT, no additional table references, and no partition restriction. Both modern truncate rewriting and the legacy fallback use that predicate. Physical truncate eligibility remains a separate decision for RETURNING, foreign keys, partitions, session settings, and other table metadata. The internal flag is renamed to `isUnrestrictedDelete` so all base-table, regular-index, IVF, MASTER, FULLTEXT, and POSTDML consumers express the actual contract. Closes matrixorigin#28309. ## Test plan ### Automated - Planner UT covers plain DELETE, ORDER BY-only, WHERE, LIMIT 0, JOIN, USING, partition restriction, multiple targets, and nil input. - Planner shape UT forces the synchronous FULLTEXT legacy fallback and asserts the origin DELETE cannot truncate and row-scoped hidden-index maintenance is retained. - Distributed SQL regression covers: - empty JOIN with `delete_opt_to_truncate=0`, verifying both base rows and FULLTEXT contents survive; - duplicate matches with truncate enabled, verifying one target row is deleted once and surviving/deleted FULLTEXT terms agree with the base table. ### Validation Linux/amd64 on 10.222.1.55, base `4fdb9e91615f9fc37703039ae28a47849206d1d6`, head `6c8f7fbe3c`: - `make clean && make -j12` - focused planner UT: pass - focused planner UT with `-race`: pass - `./pkg/sql/plan` and `./pkg/sql/colexec/postdml`: pass - `delete_multiple_table.sql` through mo-tester normal comparison mode twice on the same instance: 128 pass, 0 fail, 2 pre-existing ignored (100%); 1.283s and 1.487s - black-box FULLTEXT matrix: empty source, ON false, CROSS/RIGHT/LEFT JOIN, NULL key, derived empty source, USING, WHERE TRUE control, prepared-statement reuse, and duplicate matches: pass - black-box MASTER hidden-table counts: empty JOIN 6 -> 6; partial duplicate match 6 -> 4 while base rows 3 -> 2 - full repository `golangci-lint` 2.6.2: 0 issues - license header check: 5106 checked, 0 invalid - `git diff --check` and gofmt: pass The 55 test service and isolated data were removed after validation.
What type of PR is this?
What this PR does / why we need it
Irregular indexes currently route
DELETEthrough the legacy DML planner. That planner classified every single-target statement withoutWHERE/LIMITas an unrestricted whole-table delete, even whenTableRefscontained a JOIN or USING source. The resulting plan could truncate the base table or independently delete every hidden-index row without evaluating the join.This change establishes one shared semantic predicate for an unrestricted delete: exactly one target, no WHERE, no LIMIT, no additional table references, and no partition restriction. Both modern truncate rewriting and the legacy fallback use that predicate. Physical truncate eligibility remains a separate decision for RETURNING, foreign keys, partitions, session settings, and other table metadata.
The internal flag is renamed to
isUnrestrictedDeleteso all base-table, regular-index, IVF, MASTER, FULLTEXT, and POSTDML consumers express the actual contract.Closes #28309.
Test plan
Automated
delete_opt_to_truncate=0, verifying both base rows and FULLTEXT contents survive;Validation
Linux/amd64 on 10.222.1.55, base
4fdb9e91615f9fc37703039ae28a47849206d1d6, head6c8f7fbe3c:make clean && make -j12-race: pass./pkg/sql/planand./pkg/sql/colexec/postdml: passdelete_multiple_table.sqlthrough mo-tester normal comparison mode twice on the same instance: 128 pass, 0 fail, 2 pre-existing ignored (100%); 1.283s and 1.487sgolangci-lint2.6.2: 0 issuesgit diff --checkand gofmt: passThe 55 test service and isolated data were removed after validation.