fix(advisor/tidb): switch DDL detection to pingcap DDLNode for Tier-4… · bytebase/bytebase@ebc36f0 · GitHub
Skip to content

Commit ebc36f0

Browse files
vsai12claude
andcommitted
fix(advisor/tidb): switch DDL detection to pingcap DDLNode for Tier-4-grammar coverage (Codex P1, cumulative #30 Codex-fix-1f)
Codex caught: omni's parser rejects Tier-4-deferred DDL grammar (CREATE/ALTER/DROP SEQUENCE, FLASHBACK DATABASE/TABLE). Per invariant #2, `getTiDBOmniNodes` soft-fails on omni-rejected stmts. For builtin_prior_backup_check — a safety gate — this silently drops DDL classification on these valid tidb statements: CREATE SEQUENCE seq1 START 1; UPDATE bar SET x=1; FLASHBACK TABLE foo; DELETE FROM bar WHERE id=5; Pre-omni: pingcap parses both, classifies as DDL via DDLNode interface → mixed-DDL+DML advice fires. Post-omni: omni rejects SEQUENCE/FLASHBACK → soft-fail skips → advisor sees only UPDATE/DELETE → no DDL detected → safety gate silently misses. Empirical verification (parse-test through omni): all five inputs (CREATE/ALTER/DROP SEQUENCE, FLASHBACK DATABASE, FLASHBACK TABLE) fail omni parsing with syntax error. Fix: DDL detection switches to the `getTiDBNodes` (pingcap) path. Pingcap's DDLNode interface (via the ddlNode struct embedding in ast/base.go:81-88) catches all 22 implementers including Tier-4- deferred grammar. The advisor still uses `getTiDBOmniNodes` for per-table DML mixing detection (where omni AST shape is required); DDL detection sidesteps omni's grammar gaps. Architectural note: this dual-path approach mirrors mysql's analog, which uses mysqlparser.ExtractTables alongside the omni AST. Specialized advisors that need both full-grammar coverage AND omni-specific AST shape will need both paths until omni grammar parity catches up. Side effects: - omniIsDDLStmt helper REMOVED. Eight rounds of Codex catches on omni-only DDL enumeration (cumulative #30 Codex-fix-1c through 1e) demonstrated the brittle-enumeration anti-pattern; pingcap's authoritative DDLNode interface eliminates the maintenance burden. - TestOmniIsDDLStmt REMOVED. The helper it tested is gone. End-to-end coverage of the DDL-detection path moves to TestTiDBPriorBackupCheckAdvisor. Regression-direction pins added (TestTiDBPriorBackupCheckAdvisor case count: 14 → 16): - "CREATE SEQUENCE + UPDATE fires mixed DDL+DML via pingcap path (Codex-fix-1f)": `CREATE SEQUENCE seq1 ...; UPDATE tech_book ...;` → MUST fire. - "FLASHBACK TABLE + DELETE fires mixed DDL+DML via pingcap path (Codex-fix-1f)": `FLASHBACK TABLE tech_book TO tech_book_old; DELETE FROM orders ...;` → MUST fire. Both pins exercise the new pingcap-DDLNode resolution path. Cumulative #30 algorithm-corrections sub-fix lineage now spans eight sub-fixes: 1 — SET-clause-based target extraction 1b — distinct-base gating 1c — DDL classification (DropView + AlterDatabase) 1d — schema-qualified UPDATE target lookup 1e — schema-aware unqualified-SET resolution 1f — DDL detection via pingcap DDLNode (drops omniIsDDLStmt) 2 — case-insensitive grouping key 2-revised — DBSchema.Name default-DB Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1e7ec6c commit ebc36f0

3 files changed

Lines changed: 87 additions & 118 deletions

File tree

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

Lines changed: 44 additions & 34 deletions

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,40 @@ func TestTiDBPriorBackupCheckAdvisor(t *testing.T) {
268268
"db1.tech_book",
269269
},
270270
},
271+
{
272+
// Cumulative #30 Codex-fix-1f: Tier-4-deferred DDL
273+
// (CREATE/ALTER/DROP SEQUENCE) is omni-rejected at
274+
// parse time. Pre-fix-1f used omniIsDDLStmt on
275+
// omni-parsed stmts → soft-fail skipped the SEQUENCE
276+
// stmt → DDL detection missed → no mixed-DDL advice
277+
// despite the DML+DDL mixing. Post-fix-1f: DDL
278+
// detection uses pingcap's DDLNode interface via
279+
// `getTiDBNodes` → pingcap parses CreateSequenceStmt
280+
// successfully → DDL detected → advice fires.
281+
name: "CREATE SEQUENCE + UPDATE fires mixed DDL+DML via pingcap path (Codex-fix-1f)",
282+
statement: "CREATE SEQUENCE seq1 START 1 INCREMENT BY 1;\nUPDATE tech_book SET id = 1 WHERE id = 2;",
283+
backupDBPresent: true,
284+
wantContentSubstr: []string{
285+
"mixed DDL and DML",
286+
},
287+
},
288+
{
289+
// Cumulative #30 Codex-fix-1f: FLASHBACK family is
290+
// Tier-4-deferred grammar in omni. Pingcap handles
291+
// FLASHBACK TABLE / FLASHBACK DATABASE as DDL via
292+
// the DDLNode interface. Post-fix-1f: pingcap path
293+
// catches it; pre-fix-1f silently skipped.
294+
//
295+
// Note: pingcap classifies FLASHBACK TABLE / DATABASE
296+
// as DDL via ddlNode struct embedding. Verified by
297+
// parse-test in batch 19 reshape investigation.
298+
name: "FLASHBACK TABLE + DELETE fires mixed DDL+DML via pingcap path (Codex-fix-1f)",
299+
statement: "FLASHBACK TABLE tech_book TO tech_book_old;\nDELETE FROM orders WHERE order_id = 5;",
300+
backupDBPresent: true,
301+
wantContentSubstr: []string{
302+
"mixed DDL and DML",
303+
},
304+
},
271305
{
272306
// Cumulative #30 Codex-fix-1e: schema-aware column
273307
// resolution for unqualified SET in multi-table UPDATE.

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

Lines changed: 9 additions & 84 deletions

0 commit comments

Comments
 (0)