Skip to content

feat(plan): plan DML on FULLTEXT/vector-indexed tables with the new DML planner - #33110

Merged
mergify[bot] merged 13 commits into
matrixorigin:mainfrom
cpegeric:newdml_irregular_index
Nov 23, 2026
Merged

mergify[bot] merged 13 commits into
matrixorigin:mainfrom
cpegeric:newdml_irregular_index

Conversation

@cpegeric

@cpegeric cpegeric commented Nov 23, 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:

issue #21790 #21791 #33108

What this PR does / why we need it:

Design: docs/design/20261123-new-dml-irregular-index-maintenance.md, design revision 2 / contract R1 (review required). It records the index classes, the maintenance invariant, row-stream ownership per planner route, ordering of queued maintenance, transaction and CDC semantics, and the supported shapes.

DELETE and primary-key UPDATE on tables with FULLTEXT or vector indexes now run on the new DML planner (bind_* + MULTI_UPDATE) for every index type, and foreign key actions keep the child tables' indexes exact.

  • DELETE: tables with async indexes (HNSW, CAGRA, IVF-PQ, fulltext2, ASYNC ivfflat/fulltext) and tables with sync IVF_FLAT, FULLTEXT or MASTER indexes are planned by the new binder; sync indexes are maintained by delete-by-key sub-plans. 500k-row delete on a 1M-row table with ivfflat(128-d) + master + fulltext: 0.96 s vs 1.33 s on the legacy path.
  • Primary-key UPDATE: allowed on sync IVF_FLAT and FULLTEXT tables (previously rejected, [Bug] Synchronous FULLTEXT/IVF indexes become stale after UPDATE changes primary key #25617), including RETURNING; entries are re-keyed in the same statement.
  • Legacy-planned DELETE (foreign keys, multi-table DELETE) maintains the same indexes with the new planner's sub-plans; the legacy per-algorithm delete code is removed (about 900 lines).
  • Foreign key actions ([Bug]: Foreign key actions do not maintain FULLTEXT/IVF/MASTER indexes of child tables #33108): UPDATE on a parent maintains the child's indexes instead of rejecting; REPLACE on a parent no longer panics; CASCADE + SET NULL from the same parent row no longer drops the index entries of the nulled rows (regular secondary indexes included); self-referencing tables rebuild the indexes the cascade changes.
  • reduceSinkSinkScanNodes folds sinks in step order; map order could fold a consumer before its producer and leave a dangling sink scan (no data receiver for sink node).
  • Delete-by-key joins on hidden index tables push an exact runtime filter into the hidden-table scan.

Validation: BVT dml/delete/delete_irregular_index_sync, pessimistic_transaction/vector/delete_async_irregular_index and foreign_key/fk_irregular_index check after each statement that every hidden table has no orphan and no missing key; the dml, foreign_key, fulltext, vector, array, ddl and pessimistic_transaction suites pass; pkg/sql/plan and pkg/sql/compile unit tests pass.

GPU: gpu_cases/pessimistic_transaction/vector/vector_cagra_dml_irregular and vector_ivfpq_dml_irregular run the same DELETE, PK UPDATE and FK-action paths on CAGRA and IVF-PQ; both pass on GPU, as do the existing GPU async/delete cases (logs). The GPU build also needed createResultBatch(proc.Mp()) in cagra_create_gpu.go / ivfpq_create_gpu.go, which #33052 missed on main.

Limits: #33109 (REPLACE with a SET NULL grandchild) fails without any index and is not addressed here.

🤖 Generated with Claude Code

cpegeric and others added 7 commits November 23, 2026 11:47
Cover DELETE shapes, transactions and PK UPDATE on tables with sync
IVF_FLAT, classic FULLTEXT and MASTER indexes, and DELETE on tables with
async IVF_FLAT, FULLTEXT2 and HNSW indexes. Each statement checks that the
hidden index tables reference exactly the live primary keys.

Related to matrixorigin#21790, matrixorigin#21791.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A plain DELETE on a table with any irregular index fell back to the legacy
planner. Async (CDC-maintained) indexes need no in-statement maintenance, so
only fall back when the table has an irregular index that is not async:
HNSW, CAGRA, IVF-PQ, FULLTEXT2 and async IVF_FLAT / FULLTEXT now use the
modern binder.

Related to matrixorigin#21790, matrixorigin#21791.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
DELETE on a table with a synchronous IVF_FLAT, classic FULLTEXT or MASTER
index fell back to the legacy planner unless it had RETURNING. Materialize
the deleted rows the way DELETE ... RETURNING does and delete their hidden
index entries from that image, so every DELETE uses the modern binder. An
irregular index without modern maintenance still falls back.

Deleting 500k of 1M rows with IVF_FLAT(128), MASTER and FULLTEXT indexes
takes 0.96 s instead of 1.33 s.

Related to matrixorigin#21790, matrixorigin#21791.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…indexes

A primary-key change now re-keys synchronous IVF_FLAT and classic FULLTEXT
hidden entries in the same statement, using the delete-by-old-key and
final-image insert maintenance that MASTER already uses. This removes the
matrixorigin#25617 rejection, including for UPDATE ... RETURNING.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… sub-plans

DELETE statements the modern binder does not plan (foreign keys, multi-table
DELETE) and FK actions now maintain FULLTEXT, IVF_FLAT and MASTER indexes with
the delete-by-key and final-image insert sub-plans of the modern DML planner.
The legacy per-algorithm delete code and the unused post-DML fulltext path are
removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- UPDATE on a parent maintains the synchronous FULLTEXT, IVF_FLAT and MASTER
  indexes of the child rows its foreign key actions change, instead of
  rejecting the statement.
- REPLACE on a parent queues the child index maintenance it plans before
  createQuery for finishIrregularIndexMaintenance; planning it in place
  panicked in filter pushdown.
- A SET NULL action that excludes the CASCADE-owned rows plans its own delete
  instead of merging into the CASCADE delete, which dropped the index rebuild
  of the nulled rows (regular secondary indexes included).
- reduceSinkSinkScanNodes folds sinks in step order; folding a consumer before
  its producer in map order left a dangling sink scan.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- A root UPDATE also rebuilds the irregular indexes that its
  self-referencing ON UPDATE CASCADE / SET NULL actions change on merged rows.
- REPLACE foreign key actions see the target's irregular indexes, so a
  self-referencing cascade drops the hidden entries of the deleted rows.
- Delete-by-key joins on FULLTEXT, IVF_FLAT and MASTER hidden tables push an
  exact runtime filter into the hidden-table scan, as the removed legacy
  deletes did.
- A queued delete keeps its source projection, so the primary key stays at
  its column position after createQuery.
- One sync/async classifier serves DELETE and UPDATE routing, and one
  updated-row projection serves both delete-source layouts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify mergify Bot added kind/bug Something isn't working kind/feature kind/refactor Code refactor labels Nov 23, 2026
@matrix-meow matrix-meow added the size/XXL Denotes a PR that changes 2000+ lines label Nov 23, 2026
@mergify

mergify Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@XuPeng-SH

XuPeng-SH commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: dd1b67fe7be624e43e74bc5d5ebae0affa37b407

Review completed. Read the assessment.

@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.

mo-bot review · mo-bot-local · review

Commit: dd1b67fe7be624e43e74bc5d5ebae0affa37b407

Assessment: approve

Revision 2 resolves the prior design finding by documenting which row stream owns each hidden-index write, how deferred maintenance preserves column positions, and how rollback and CDC handle the resulting writes. The implementation reuses the existing maintenance helpers across planner routes and keeps asynchronous indexes on CDC.

Model: gpt-6.2-sol / xhigh

Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3

Validation:

  • Nine focused planner tests passed, including legacy DELETE rejection for unsupported synchronous indexes, runtime-filter association, and sink folding. See planner-focused.jsonl and receipt checks/1795465006194406160-5.json.

  • All 404 checks passed across the three shipped SQL cases for synchronous DML, foreign-key actions, and asynchronous DELETE. See cpu-bvt.jsonl, the three mo-tester reports, and receipt checks/1795465133500498402-5.json.

  • Verified the frozen source, isolation preflight, native inputs, receipt correspondence, and all six discussion dispositions. See verification.log and receipt checks/1795465273662576721-6.json.

  • The author supplied passing real-device logs for eight CAGRA and IVF-PQ SQL cases and the GPU classifier test. The GPU fixtures and build fixes match the tested revision. The later legacy classifier change preserves the registered GPU algorithms’ asynchronous path.

Limitations:

  • Local SQL validation used one embedded CPU CN. GPU execution relied on the author’s logs, and the reported DELETE speedup was outside local validation.

  • The retained plain-child controls reproduced the inherited two-cascade REPLACE planner rejection on the prior reviewed head and the merge base. Revision 2 also records the SET NULL grandchild and overlapping indirect-action limitations.

@mergify mergify Bot added the queued label Nov 23, 2026
@mergify

mergify Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

✅ Merged into main as 66263ee at 21:37 UTC

1 h 15 min in the queue, 1 h 14 min of it CI.

So far

  • ✅ Entered the queue Mon 23 Nov, 20:22 · rule main · triggered by rule Automatic queue on approval for main
  • ✅ Passed · in place
  • ✅ Merged 21:37 · 66263ee · squash
3 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-success = CI Required
    • check-neutral = CI Required
    • check-skipped = CI Required

Times in UTC · dashboard · how the merge queue works

This branch was previously deployed

1 inactive deployment
ci — 62317141 Deployed Nov 23, 2026 by mergify[bot]
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/feature kind/refactor Code refactor size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants