fix(advisor/tidb): SET-clause target extraction + canonicalized group… · bytebase/bytebase@5eb842b · GitHub
Skip to content

Commit 5eb842b

Browse files
vsai12claude
andcommitted
fix(advisor/tidb): SET-clause target extraction + canonicalized grouping key (Codex P2 ×2, cumulative #30 algorithm corrections)
Codex caught two real bugs in the batch 19 reshape: 1. UPDATE table refs were taken from the full Tables list, including JOIN-only read-only tables. For `UPDATE t1 JOIN t2 ON ... SET t1.col = ...; DELETE FROM t2 ...` this produced a false mixed-DML warning on t2 — only t1 was actually mutated. 2. Grouping key `fmt.Sprintf("%s.%s", db, table)` used raw strings, splitting equivalent references into different buckets: - Unqualified `tech_book` vs qualified `mydb.tech_book` - Case-different `tech_book` vs `Tech_Book` These false-negatives weakened the safety gate. Codex-fix-1: SET-clause-based target extraction. New file-local helpers: - omniBuildTableAliasMap(tables) builds an alias→base-table lookup from update.Tables (walks TableRef + JoinClause; SubqueryExpr contributes nothing per cumulative #26). - omniExtractUpdateTargets(setList, aliasMap) walks SET assignments; qualified `t.col = ...` resolves via aliasMap; unqualified `col = ...` falls through only when aliasMap has exactly 1 entry (single- target UPDATE); otherwise skipped (multi-target UPDATE with unqualified SET is ambiguous without schema info — false-negative is preferable to false-positive at this boundary). The UpdateStmt arm now uses omniExtractUpdateTargets. The DeleteStmt arm still uses Tables directly (verified omni parsenodes.go:123 — DELETE's Tables is the mutation target set; Using[] is filter-only). Codex-fix-2: canonicalized grouping key. The per-table grouping key now lowercases both segments AND substitutes checkCtx.CurrentDatabase when the table reference has no explicit database qualifier. Equivalent references group into the same bucket; mixed-DML detection no longer misses on common authoring patterns. Regression-direction pins added to TestTiDBPriorBackupCheckAdvisor: - "UPDATE-JOIN + DELETE-on-joined-table — no false-positive (Codex-fix-1)": `UPDATE tech_book JOIN orders SET tech_book.name = 'x'; DELETE FROM orders WHERE order_id = 5;` — must NOT fire mixed-DML on orders (only tech_book is the UPDATE target). - "case-insensitive grouping — Tech_Book ≡ tech_book (Codex-fix-2)": `UPDATE tech_book ...; DELETE FROM Tech_Book ...;` — must fire mixed-DML (same logical table). Test count: 6 → 8 cases. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 7e02cac commit 5eb842b

2 files changed

Lines changed: 143 additions & 2 deletions

File tree

‎backend/plugin/advisor/tidb/advisor_builtin_prior_backup_check.go‎

Lines changed: 113 additions & 2 deletions

‎backend/plugin/advisor/tidb/tidb_rules_test.go‎

Lines changed: 30 additions & 0 deletions

0 commit comments

Comments
 (0)