Repository navigation
fix(sql): validate forward foreign keys at DDL admission - #29867
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Final model review: APPROVE at 39e5732ec231d4e6c787e995471b11f3ddbba76f (actual gpt-6.1-sol / xhigh).
The first overall review found that optimized DELETE could change an incoming FK's selected key from z to a. Real SQL reproduced the issue. The correction validates and retains that key under the existing synchronous replacement receipt. Transactional DELETE rollback, committed replacement, index protection and FK enforcement pass; explicit DROP/CREATE keeps normal new-parent key selection.
All accepted findings are reconciled. The change reuses existing admission, snapshot, FK binding, checkpoint and rollback owners; no additional store or state machine was introduced. Eight owning packages passed race checks, with deterministic public SQL controls and bounded exact-test repetitions. Affected incremental vet/configured lint/molint passed. These results are local, not a full CI claim.
5,000 actual tables: combined DROP66.806s versus baseline101.825/101.924s (~34.4% lower elapsed), committed catalog5000→0. Setup43.233s versus40.020/40.204s (~7.5–8% higher in these runs, without causal attribution); whole-run peak RSS+0.61%. Representative visibility/cache combinations were exercised; Cartesian completeness is not claimed.
No review blocker remains. Published-branch CI is pending.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review of 4022729da24d71b082c22b52aaed3faba2b77ea5...39e5732ec231d4e6c787e995471b11f3ddbba76f: APPROVE on reviewed code; CI is still pending. No new blocking correctness, liveness or engineering-quality finding. This is a fresh direct review; no subagent was used. Production and committed tests were unchanged during review.
The complete change map covers 42 files, separately assessed: implementation/protocol 21 files (+1034/-301), tests 19 (+1117/-21), design document 1 (+59), generated protobuf 1 (+1314/-1183). All 42 current file fingerprints match the previously validated delivery. The generated churn is message fields, descriptor/serialization and mechanical variable renumbering.
Design and ownership:
- Planning retains participant hints and observed name binding; execution owns current FK declarations, column IDs and complete constraints. The old post-effects child lookup/publication loop is removed. Both positive and negative dependencies participate in admission; the existing retry owner verifies the fixed name domain, and compile reuse clears the admission bit. Deep-copy uses the existing complete protobuf clone.
- Current FK decoding, column/key validation, index dependency checking, snapshot advancement and fatal-error classification have shared owners. The receipt is scoped to actor, transaction, target and synchronous lifetime. TRUNCATE/internal optimized DELETE preserve the selected key; ordinary explicit DROP/CREATE legitimately makes a new selection.
- DROP DATABASE delegates index-catalog deletion to its existing transactional bulk owner using the resolved database ID. Ordinary DROP TABLE and plugin/physical/PITR cleanup remain owned by their existing paths. The historical checkpoint and pressure-classification changes have causal baseline evidence, as required by the requested scope.
Unhappy-path audit of the changed closure:
| Invariant | Ownership/termination evidence | Result |
|---|---|---|
| Q1: one effective cleanup owner | Key vectors/packers/results have scoped cleanup; SQL admission spans preparation and cleanup; fatal errors seal the operator and drain into its existing once-only rollback owner; receipts expire and compile state resets | No new violation found |
| Q2: waits terminate without a reverse lock cycle | Retained C/G/D admission and names under G use FastFail; fresh DROP INDEX waits on the physical table before D/T; context/deadline reaches lock core; callbacks execute outside tracker mutex; nested fatal rollback does not wait on its own token | Existing cancellation/timeout/progress evidence remains valid |
| Q3: retained state is bounded | Name domains are statement-owned, retry cannot silently expand them; child bindings live only for execution; existing retry queue/budget and partition identity/deletion precedence are retained | No new persistent accumulation owner |
Fresh public SQL counterexamples, using two authenticated CNs and deterministic real lock-wait scheduling:
- While parent CREATE waits, replace the child with a different FK name and column plus ON DELETE CASCADE. Both CREATEs succeed; actual new table ID, catalog and SHOW CREATE agree; the new column enforces FK and CASCADE deletes the child.
- Replace the child with a BIGINT FK while the queued parent plan uses INT. CREATE fails before publication, no partial parent remains, and a subsequent compatible BIGINT parent succeeds with correct enforcement/actions.
- With PITR protection alone, TRUNCATE then restore, and DROP DATABASE then restore, recover the row and unique constraint. No named snapshot is used by this probe.
These three probes passed normally (10.060s total) and each twice under -race (17.520s total). They are review-only overlays, not newly committed regression tests. Compact durable coverage for these extra cases would be useful, especially PITR; the public recovery gap is now experimentally checked. Exact source/probes/logs are retained under /home/xupeng/.codex/issue-to-pr/matrixone/issue29852/deep-review-*.
Reused evidence: eight owning packages passed race checks; original stale-child and missing-parent/empty-incoming schedules, pending TRUNCATE/COPY, selected-key preservation, rollback, index waiter cancellation/deadline, cold/warm historical checkpoint and catalog cleanup controls passed. Incremental vet/configured lint/molint passed. This review found no semantic input change invalidating those results.
Prior comments: the earlier model's optimized-DELETE selected-key defect and incorrect ordinary DROP/CREATE test oracle are closed. There are no outstanding inline code comments on this PR at review time. The issue observations remain correctly calibrated: WriterFair=false alone is not evidence of a new starvation failure; query counts alone are not a performance regression. Target lock cancellation/deadline is covered, and PITR recovery was additionally challenged above. Sustained-contention fairness and uncontended TRUNCATE throughput were not established by these tests.
Performance: 5000 actual tables, combined DROP 66.806s versus baseline 101.825/101.924s (~34.4% less elapsed), committed catalog 5000→0. CREATE setup was 43.233s versus 40.020/40.204s (~7.5–8% higher in the available runs); the evidence does not isolate its cause or establish a statistically stable regression. Whole-run peak RSS +0.61% is not DROP-isolated memory. Do not claim universal DDL performance improvement.
Build and Connector/J CI passed; UT, coverage, ARM SCA and BVT were still running when checked. This code verdict does not claim full CI success or exhaustive coverage of every cache/topology combination.
aunjgr
left a comment
There was a problem hiding this comment.
Reviewed head 00afb6d, with merge-base 61d8e28 against the current declared main base. Reviewed the v5 design and recorded amendments before the implementation. No blocking finding.
The key invariant is now enforced at admission/execution rather than by trusting planned child bindings. Negative parent-name dependencies are retained; binding identity and commit watermarks invalidate stale plans; incoming repair reads current declarations and physical definitions, preserves unrelated constraints, and updates each child once. Retry carryover remains restricted to the admitted CREATE domain.
I traced the associated ownership changes: DROP INDEX waits for physical definition ownership before taking nonwaiting names; internal replacements borrow a scoped outer receipt/frontier; fatal internal SQL seals the existing transaction drain owner before callbacks can suppress the error; borrowed Compile/Reset cannot replay or roll back the caller's statement. Ordered MERGE/PICK delivery and frontend workspace boundaries address the previously failing partial-effect path without adding a separate retry owner or whole-result spool.
Checkpoint creation/deletion and live-logtail cutoffs remain distinct; the changed object-boundary checks preserve unrelated tombstones. Database index cleanup remains transactional and database-scoped. CTAS AST/warning isolation, task completion fencing, optional protobuf fields, and the cancellation-fixture amendments align with their existing consumers.
Validation: reused the documented normal/race, deterministic negative-control, two-CN SQL/BVT, rollback, and cold-snapshot evidence after inspecting the corresponding tests. Current-head build, UT, SCA, coverage, pessimistic and proxy BVT checks pass. I did not independently rerun the native cluster suite or performance measurements. Skipped upgrade/platform jobs are not runtime evidence; the disclosed throughput/fairness and mixed-version limitations remain limitations, not additional approval claims.
00afb6d to
b313a20
Compare
|
mo-bot review · Commit: Assessment: approve 完成全部 73 文件、设计、调用链及冻结评论审查。当前实现复用既有准入、重试、事务回滚和存储职责,相关具体问题已有代码与回归测试闭环,未发现需修改的已确认缺陷。 Model: Session: Validation:
Limitations:
|
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: b313a20779cb96793b6b8643e5d616e669d3975f
Assessment: approve
完成全部 73 文件、设计、调用链及冻结评论审查。当前实现复用既有准入、重试、事务回滚和存储职责,相关具体问题已有代码与回归测试闭环,未发现需修改的已确认缺陷。
Model: gpt-6-astra / xhigh
Session: 01a12d8f-8e48-7622-ad17-b605f08450ce · slot 1 · generation 0
Validation:
-
核实 checkout 为指定 HEAD,源码保持干净;恢复上一轮有效审查证据,未将中断的审查当作既有批准。
-
审查覆盖 FK 正负依赖、绑定失效、内部替换、DROP INDEX 锁顺序、嵌套执行取消与回滚、MERGE 部分失败、检查点可见性、CTAS 和任务完成同步。
-
分别审视 37 个实现文件、34 个测试文件、设计文档和生成代码;核对真实 SQL 入口、失败后此前写入保留、暂存清理、锁释放及 prepared/Reset 行为。
-
静态协议核验通过:描述符仅新增 CreateTable 的 16、17 号字段,序列化、大小计算和反序列化一致。
-
冻结证据明确关联当前 HEAD:构建、Ubuntu/x86 UT、ARM64 SCA、覆盖率、Connector/J、proxy 与 pessimistic 多 CN BVT 均成功。
-
结合当前测试复用作者记录的 normal/race、负向对照及双 CN 验证;历史运行未冒充当前 HEAD 的新执行。本轮未运行 native 测试或使用遗留二进制。
-
完整审查记录:/home/xupeng/.local/state/mo-bot/jobs/26c14eb12bb72c614d575388/attempt-2/review-record.md;静态核验和逐文件清单保存在同目录。
Limitations:
-
冻结材料未包含关联 issue 的独立正文;行为契约依据 PR 的复现描述、设计、评论和回归测试核对。
-
未独立重跑 native 集群或性能测试;CI 证据是当前 HEAD 的检查结论,不包含完整逐测试日志。
-
历史性能数据存在明确成本:CTAS 规划约增加 4.17%,部分 MERGE 样本延迟约增加 24%;DROP 的历史收益不代表其他路径无退化。持续竞争公平性及无竞争 TRUNCATE 吞吐未测。
-
跳过的升级、Darwin、optimistic 作业及 ARM 静态分析不能证明对应运行时兼容性。
-
此前七项严格 JSON/JDBC 元数据差异仍未归因,未计为通过;任务同步保留不可达节点下既有的 best-effort 语义。
iamlinjunhong
left a comment
There was a problem hiding this comment.
审查结论:APPROVE。针对 head b313a20779cb96793b6b8643e5d616e669d3975f,未发现可从当前代码确认的 P0、P1、P2 或 P3 问题。
本轮独立检查了全部 73 个变更文件的完整 diff、关键实现和相关测试。读取远端 main 035a5b61ba84ffc7dd2193135a7b170af04a4bff,与 head 的 merge-base 为 a5b7d1e75fde337400d4f0c71932a0ebbaff0b30;远端比较的全部文件 SHA 和增删统计与派发数据一致,按需获取的变更实现文件均通过 Git blob SHA 校验。已读取历史 reviews、inline comments 和 PR conversation,没有本账号的上轮 review,按首次审查规则处理。
重点核对了 CREATE 的正负外键名称依赖、绑定与提交水位失效、当前子表约束的重新绑定和完整发布;DROP INDEX 的物理锁与名称锁顺序;TRUNCATE/COPY 的替换凭证、所选引用键和 catalog-only 声明保留;嵌套 SQL 的准入、重试、致命错误封闭和回滚;MERGE/PICK 的同步应用及前端语句 workspace 边界;checkpoint 对象可见性和 tombstone 删除范围;数据库索引目录批量清理、CTAS AST/警告隔离、任务完成同步及锁重试内存压力分类。未确认新增的正确性、并发、生命周期或性能缺陷。protobuf 静态验证确认只新增 CreateTable 的 16、17 号字段,既有描述符保持一致,其他 packed 编码 diff 仅为生成变量重编号。
回归测试包含跨 CN 的外键缺失/替换调度、内部替换、所选键保留、DROP INDEX 取消与超时、借用 CREATE 保留此前写入、MERGE 部分失败回滚、冷 checkpoint 历史读取及数据库清理失败路径。派发 CI 数据中 29 项均已结束:13 success、14 skipped、2 neutral,没有失败;mergeable=true,mergeable_state=behind。
验证范围:本轮为静态审查及协议校验。派发目录没有 Git 仓库或对象库,因此使用完整 diff 和指定 SHA 的按需 blob,未 clone 或完整 checkout,未独立运行 Go/native 集群测试或性能基准。CI 结论来自派发数据;跳过的检查和作者历史性能数据不计为本轮运行通过。
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #29852
What this PR does / why we need it:
A parent CREATE could apply its planned incoming FK to a replacement child that no longer declared it. Stale negative dependencies could also leave a newly available parent or child unbound. CREATE admits its declared name domain, checks the actual binding/commit watermark, and uses the existing applied-logtail/replan owner before effects. Incoming repair binds current catalog declarations against actual child definitions, preserves complete unrelated constraints, and updates each child once. Planner and executor share FK decoding and validation.
Lifecycle transitions retain the existing admission, SQL token and deferred rollback owners. Retained transitions use FastFail; DROP INDEX waits for its provisional physical definition before acquiring names. Internal TRUNCATE/COPY borrow a synchronous, tenant/transaction/target-scoped replacement receipt. Pending declarations and selected referenced keys/actions survive internal replacement, including optimized whole-table DELETE. Explicit DROP/CREATE makes the normal new-parent selection. Fatal nested errors seal the transaction even if callbacks catch them, preserve their original error, and reject subsequent SQL before workspace preparation.
DROP DATABASE delegates index-catalog deletion to the existing transactional database bulk owner, removing redundant per-table catalog deletes. Table physical/plugin/history cleanup keeps its existing owner. Historical checkpoint replay retains durable appendable data/tombstone objects; creation registers/prefetches without reclamation when deletion time is absent, and deletion scans stop at the object boundary. Checkpoint DeleteTime and live startTS cutoffs stay distinct. Lock pressure classification uses available memory headroom within existing retry budgets and queues.
Planning and execution boundaries
Current validation
Rebased onto pinned main
61d8e2887f0ae5b63e3baa7b399e3b10b9c47d6a. Go 1.27.1, Linux amd64, matching native libraries and repositorymo-cgo-testwrapper. Existing 67-file reviewed content survived the rebase unchanged; the final intended change map contains 73 files.nometa): 0 failed/ignored/abnormal statements, verified cleanup, both services exit 0. The fixture reuses its unique-conflict setup to cover prior INSERT, partial MERGE failure, destination/prior rows, stage cleanup and COMMIT.Reused earlier evidence
Unchanged warning/task/cancellation inputs retain their prior validation: owning normal/race and optools normal/race, failed negative controls for duplicate CTAS warnings and omitted task fence, two-CN JSON/task data/error/warning BVT 234/234 twice, and both-direction task-storage reads after 20 failed executions plus one timeout without polling. Join cancellation passes 20 normal and 20 race repetitions; its too-short-grace control forces KILL and retained artifacts. Bash syntax and incremental ShellCheck pass. These are recorded earlier runs, not fresh new-head executions.
The earlier strict JSON metadata run had seven JDBC metadata differences (length/prepared label); those comparisons are not claimed passed or attributed to this PR. The latest checked old-head CI independently passed the previous warning/task/cancellation corrections.
Performance, compatibility and limits
Historical matched 5000-table runs: DROP 66.806s versus baseline 101.825/101.924s (~34.4% lower elapsed), committed catalog 5000→0. CREATE setup 43.233s versus 40.020/40.204s; whole-run peak RSS +0.61% is not DROP-isolated memory. These measurements were not repeated for this CI correction; the database bulk cleanup path is unchanged.
Previously measured CTAS copying adds 2936B/37 allocations and ~4.17% planner elapsed. Ordered online MERGE samples showed ~0%/24%/24% median latency differences for 1/128/2048 rows; workload-wide performance neutrality is not claimed. Current warning/task corrections add no per-row SELECT/DML work; failed manual task execution now pays one existing cluster synchronization. The current ownership amendment adds one bounded boundary update per owning frontend statement and at most one existing CREATE replan before effects; it adds no per-row work, cache, worker or lock held across dispatch. Unreachable metadata writers retain the helper's best-effort semantics. Sustained-contention fairness and uncontended TRUNCATE throughput remain unmeasured.
No mixed-version upgrade protocol is introduced; declarations authored with foreign_key_checks=0 are not newly validated. Cache/topology Cartesian completeness and ARM runtime validation are not claimed.
Latest checked CI at
8c653aaa7bcb42107f6e17b4dff5fc6873fd3bcc(run 38138857769) passed build, Ubuntu/x86 UT, ARM64 SCA, UT coverage and pessimistic multi-CN BVT. Proxy BVT exposed nested CREATE retry removing earlier MERGE stages. This correction repairs that owner and the separately reproduced frontend workspace boundary defect. Aggregate coverage failed from missing producer output; no coverage verdict was computed. New-head remote CI remains pending after push.Design amendments use explicitly selected gpt-6.1-sol/xhigh, sessions
01a12b76-f0b5-7eb0-b176-bfd8722687efand01a12b90-b7bb-7750-ba0f-36f601c7521c. Final overall review session01a12ba5-7082-7ad2-8474-ca93c960d788reports APPROVE — no material blocker, reconciled against all 73 final file hashes and amendment fingerprint540ba1a5….