Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor(advisor/tidb): migrate index key-number + total-number pair to omni AST + cumulative #28 (Phase 1.5 §1.5.3 batch 17) (#20323)

Vincent Huang70b74f7f7ce8
diff --git a/backend/plugin/advisor/tidb/advisor_index_key_number_limit.go b/backend/plugin/advisor/tidb/advisor_index_key_number_limit.go
index 6584d39cae..f88e1da520 100644
--- a/backend/plugin/advisor/tidb/advisor_index_key_number_limit.go
+++ b/backend/plugin/advisor/tidb/advisor_index_key_number_limit.go
@@ -1,39 +1,45 @@
package tidb
-// Framework code is generated by the generator.
-
import (
"context"
"fmt"
+ "github.com/bytebase/omni/tidb/ast"
"github.com/pkg/errors"
- "github.com/bytebase/bytebase/backend/plugin/advisor/code"
-
- "github.com/pingcap/tidb/pkg/parser/ast"
-
"github.com/bytebase/bytebase/backend/common"
storepb "github.com/bytebase/bytebase/backend/generated-go/store"
"github.com/bytebase/bytebase/backend/plugin/advisor"
+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"
)
var (
_ advisor.Advisor = (*IndexKeyNumberLimitAdvisor)(nil)
- _ ast.Visitor = (*indexKeyNumberLimitChecker)(nil)
)
func init() {
advisor.Register(storepb.Engine_TIDB, storepb.SQLReviewRule_INDEX_KEY_NUMBER_LIMIT, &IndexKeyNumberLimitAdvisor{})
}
-// IndexKeyNumberLimitAdvisor is the advisor checking for index key number limit.
-type IndexKeyNumberLimitAdvisor struct {
-}
-
-// Check checks for index key number limit.
+// IndexKeyNumberLimitAdvisor flags index/constraint declarations whose
+// number of key columns exceeds the configured maximum.
+type IndexKeyNumberLimitAdvisor struct{}
+
+// Check fires on per-constraint key counts in CREATE TABLE, CREATE
+// INDEX, and ALTER TABLE ADD CONSTRAINT. No cross-stmt state. Recipe A.
+//
+// Cumulative #2 coverage: pingcap-tidb's pre-omni indexKeyNumber()
+// helper handled `ConstraintUniq`, `ConstraintUniqKey`, and
+// `ConstraintUniqIndex` as three distinct enum values. Omni unifies
+// all three under `ConstrUnique` (verified empirically: parsing
+// `UNIQUE(a)`, `UNIQUE KEY uk(a)`, `UNIQUE INDEX ui(a)` all yields
+// `Type=ConstrUnique`). The omni port matches the single arm and
+// covers all three forms mechanically — NOT a regression.
+//
+// Cumulative #19 (case-sensitivity): pre-omni used `.O` throughout
+// (no `.L`). Omni preserves user case via direct strings. Mechanical.
func (*IndexKeyNumberLimitAdvisor) Check(_ context.Context, checkCtx advisor.Context) ([]*storepb.Advice, error) {
- stmtList, err := getTiDBNodes(checkCtx)
-
+ stmts, err := getTiDBOmniNodes(checkCtx)
if err != nil {
return nil, err
}
@@ -46,98 +52,127 @@ func (*IndexKeyNumberLimitAdvisor) Check(_ context.Context, checkCtx advisor.Con
if numberPayload == nil {
return nil, errors.New("number_payload is required for index key number limit rule")
}
- checker := &indexKeyNumberLimitChecker{
- level: level,
- title: checkCtx.Rule.Type.String(),
- max: int(numberPayload.Number),
- }
-
- for _, stmt := range stmtList {
- checker.text = stmt.Text()
- checker.line = stmt.OriginTextPosition()
- (stmt).Accept(checker)
+ maximum := int(numberPayload.Number)
+ if maximum <= 0 {
+ return nil, nil
}
+ title := checkCtx.Rule.Type.String()
- return checker.adviceList, nil
-}
-
-type indexKeyNumberLimitChecker struct {
- adviceList []*storepb.Advice
- level storepb.Advice_Status
- title string
- text string
- line int
- max int
-}
-
-type indexData struct {
- table string
- index string
- line int
-}
-
-// Enter implements the ast.Visitor interface.
-func (checker *indexKeyNumberLimitChecker) Enter(in ast.Node) (ast.Node, bool) {
- var indexList []indexData
-
- appendIndexItem := func(table, index string, line int) {
- indexList = append(indexList, indexData{
- table: table,
- index: index,
- line: line,
- })
+ type violation struct {
+ table string
+ index string
+ line int
}
+ var hits []violation
- switch node := in.(type) {
- case *ast.CreateTableStmt:
- for _, constraint := range node.Constraints {
- if checker.max > 0 && indexKeyNumber(constraint) > checker.max {
- appendIndexItem(node.Table.Name.O, constraint.Name, constraint.OriginTextPosition())
+ for _, ostmt := range stmts {
+ switch n := ostmt.Node.(type) {
+ case *ast.CreateTableStmt:
+ if n.Table == nil {
+ continue
}
- }
- case *ast.CreateIndexStmt:
- if checker.max > 0 && len(node.IndexPartSpecifications) > checker.max {
- appendIndexItem(node.Table.Name.O, node.IndexName, checker.line)
- }
- case *ast.AlterTableStmt:
- for _, spec := range node.Specs {
- if spec.Tp == ast.AlterTableAddConstraint {
- if checker.max > 0 && indexKeyNumber(spec.Constraint) > checker.max {
- appendIndexItem(node.Table.Name.O, spec.Constraint.Name, checker.line)
+ for _, c := range n.Constraints {
+ if c == nil {
+ continue
+ }
+ if omniIndexKeyCount(c) > maximum {
+ hits = append(hits, violation{
+ table: n.Table.Name,
+ index: omniConstraintAdviceName(c),
+ line: ostmt.AbsoluteLine(c.Loc.Start),
+ })
+ }
+ }
+ case *ast.CreateIndexStmt:
+ if n.Table == nil {
+ continue
+ }
+ if len(n.Columns) > maximum {
+ hits = append(hits, violation{
+ table: n.Table.Name,
+ index: n.IndexName,
+ line: ostmt.FirstTokenLine(),
+ })
+ }
+ case *ast.AlterTableStmt:
+ if n.Table == nil {
+ continue
+ }
+ stmtLine := ostmt.FirstTokenLine()
+ for _, cmd := range n.Commands {
+ if cmd == nil || cmd.Constraint == nil {
+ continue
+ }
+ // Cumulative #17 sibling-parity convention: tidb omni
+ // emits only ATAddConstraint for all `ALTER TABLE ADD
+ // ...` forms today, but the dual arm is the recommended
+ // convention (batch 4 naming-trio + batch 8 index spine
+ // + utils.go collectIndexFamilyAlterTable) for forward-
+ // compat against grammar evolution that may start
+ // emitting ATAddIndex.
+ if cmd.Type != ast.ATAddConstraint && cmd.Type != ast.ATAddIndex {
+ continue
+ }
+ if omniIndexKeyCount(cmd.Constraint) > maximum {
+ hits = append(hits, violation{
+ table: n.Table.Name,
+ index: omniConstraintAdviceName(cmd.Constraint),
+ line: stmtLine,
+ })
}
}
+ default:
}
- default:
}
- for _, index := range indexList {
- checker.adviceList = append(checker.adviceList, &storepb.Advice{
- Status: checker.level,
+ adviceList := make([]*storepb.Advice, 0, len(hits))
+ for _, h := range hits {
+ adviceList = append(adviceList, &storepb.Advice{
+ Status: level,
Code: code.IndexKeyNumberExceedsLimit.Int32(),
- Title: checker.title,
- Content: fmt.Sprintf("The number of index `%s` in table `%s` should be not greater than %d", index.index, index.table, checker.max),
- StartPosition: common.ConvertANTLRLineToPosition(index.line),
+ Title: title,
+ Content: fmt.Sprintf("The number of index `%s` in table `%s` should be not greater than %d", h.index, h.table, maximum),
+ StartPosition: common.ConvertANTLRLineToPosition(h.line),
})
}
-
- return in, false
+ return adviceList, nil
}
-// Leave implements the ast.Visitor interface.
-func (*indexKeyNumberLimitChecker) Leave(in ast.Node) (ast.Node, bool) {
- return in, true
-}
-
-func indexKeyNumber(constraint *ast.Constraint) int {
- switch constraint.Tp {
- case ast.ConstraintIndex,
- ast.ConstraintPrimaryKey,
- ast.ConstraintUniq,
- ast.ConstraintUniqKey,
- ast.ConstraintUniqIndex,
- ast.ConstraintForeignKey:
- return len(constraint.Keys)
+// omniIndexKeyCount returns the number of key columns declared by the
+// given constraint. INDEX/PK/UNIQUE store keys in `IndexColumns`;
+// FOREIGN KEY stores its local columns in `Columns []string` with
+// `IndexColumns` empty (verified empirically).
+func omniIndexKeyCount(c *ast.Constraint) int {
+ if c == nil {
+ return 0
+ }
+ switch c.Type {
+ case ast.ConstrIndex, ast.ConstrPrimaryKey, ast.ConstrUnique:
+ return len(c.IndexColumns)
+ case ast.ConstrForeignKey:
+ return len(c.Columns)
default:
return 0
}
}
+
+// omniConstraintAdviceName returns the constraint name suitable for
+// embedding in advice content. Falls back to "PRIMARY" for unnamed
+// PRIMARY KEY constraints (cumulative #28: pingcap-tidb accepted the
+// non-standard `PRIMARY KEY index_name (cols)` extension and captured
+// the index_name; omni follows standard MySQL grammar where PRIMARY
+// KEY doesn't accept an index_name and silently drops it. "PRIMARY"
+// is MySQL's canonical internal name for the primary key — better UX
+// than the empty backticks the raw `c.Name` would produce).
+func omniConstraintAdviceName(c *ast.Constraint) string {
+ if c == nil {
+ return ""
+ }
+ if c.Name != "" {
+ return c.Name
+ }
+ if c.Type == ast.ConstrPrimaryKey {
+ return "PRIMARY"
+ }
+ return ""
+}
diff --git a/backend/plugin/advisor/tidb/advisor_index_total_number_limit.go b/backend/plugin/advisor/tidb/advisor_index_total_number_limit.go
index e1c1a4ec1d..8baa6a65ce 100644
--- a/backend/plugin/advisor/tidb/advisor_index_total_number_limit.go
+++ b/backend/plugin/advisor/tidb/advisor_index_total_number_limit.go
@@ -1,41 +1,61 @@
package tidb
-// Framework code is generated by the generator.
-
import (
"context"
"fmt"
"slices"
+ "github.com/bytebase/omni/tidb/ast"
"github.com/pkg/errors"
- "github.com/bytebase/bytebase/backend/plugin/advisor/code"
-
- "github.com/pingcap/tidb/pkg/parser/ast"
-
"github.com/bytebase/bytebase/backend/common"
storepb "github.com/bytebase/bytebase/backend/generated-go/store"
"github.com/bytebase/bytebase/backend/plugin/advisor"
- "github.com/bytebase/bytebase/backend/store/model"
+ "github.com/bytebase/bytebase/backend/plugin/advisor/code"
)
var (
_ advisor.Advisor = (*IndexTotalNumberLimitAdvisor)(nil)
- _ ast.Visitor = (*indexTotalNumberLimitChecker)(nil)
)
func init() {
advisor.Register(storepb.Engine_TIDB, storepb.SQLReviewRule_INDEX_TOTAL_NUMBER_LIMIT, &IndexTotalNumberLimitAdvisor{})
}
-// IndexTotalNumberLimitAdvisor is the advisor checking for index total number limit.
-type IndexTotalNumberLimitAdvisor struct {
-}
-
-// Check checks for index total number limit.
+// IndexTotalNumberLimitAdvisor flags tables whose total index count
+// (read from FinalMetadata) exceeds the configured maximum, gated on
+// the reviewed statements actually touching the table with an
+// index-creating operation.
+type IndexTotalNumberLimitAdvisor struct{}
+
+// Check tracks which tables had an index-creating operation across
+// the reviewed statements (Recipe A; cross-stmt `lineForTable`
+// aggregator), then for each such table queries FinalMetadata for
+// the final index count.
+//
+// Per-arm state-mutation semantics (cumulative #25/#27 audit):
+// - CreateTableStmt: lineForTable[name] = stmtLine (UNCONDITIONAL —
+// creates the table itself; counts as a touch).
+// - CreateIndexStmt: lineForTable[name] = stmtLine (UNCONDITIONAL).
+// - ATAddColumn (inner loop over columns): if any new column has an
+// inline PRIMARY KEY or UNIQUE constraint → record and break
+// (FIRST-violating-column wins; subsequent index-creating columns
+// in the same grouped form don't add additional touches; pre-omni
+// `break` after `createIndex(column)` returned true preserved).
+// - ATAddConstraint: if constraint creates an index → record
+// (conditional; ConstrIndex / ConstrPrimaryKey / ConstrUnique /
+// ConstrFulltextIndex are index-creating; FK / Check / Spatial
+// are NOT, matching pre-omni scope).
+// - ATChangeColumn / ATModifyColumn: if new column def declares
+// inline PRIMARY KEY or UNIQUE → record (conditional).
+//
+// Cumulative #2 coverage: pingcap's ConstraintUniq / ConstraintUniqKey
+// / ConstraintUniqIndex (3 distinct) unify under omni `ConstrUnique`;
+// pingcap's `ConstraintKey` + `ConstraintIndex` unify under omni
+// `ConstrIndex` (verified empirically). Single-arm port covers all
+// 6 pingcap constraint forms mechanically.
func (*IndexTotalNumberLimitAdvisor) Check(_ context.Context, checkCtx advisor.Context) ([]*storepb.Advice, error) {
- stmtList, err := getTiDBNodes(checkCtx)
-
+ stmts, err := getTiDBOmniNodes(checkCtx)
if err != nil {
return nil, err
}
@@ -48,139 +68,131 @@ func (*IndexTotalNumberLimitAdvisor) Check(_ context.Context, checkCtx advisor.C
if numberPayload == nil {
return nil, errors.New("number_payload is required for index total number limit rule")
}
- checker := &indexTotalNumberLimitChecker{
- level: level,
- title: checkCtx.Rule.Type.String(),
- max: int(numberPayload.Number),
- lineForTable: make(map[string]int),
- finalMetadata: checkCtx.FinalMetadata,
- }
-
- for _, stmt := range stmtList {
- checker.text = stmt.Text()
- checker.line = stmt.OriginTextPosition()
- (stmt).Accept(checker)
+ maximum := int(numberPayload.Number)
+ title := checkCtx.Rule.Type.String()
+
+ lineForTable := make(map[string]int)
+ for _, ostmt := range stmts {
+ stmtLine := ostmt.FirstTokenLine()
+ switch n := ostmt.Node.(type) {
+ case *ast.CreateTableStmt:
+ if n.Table != nil {
+ lineForTable[n.Table.Name] = stmtLine
+ }
+ case *ast.CreateIndexStmt:
+ if n.Table != nil {
+ lineForTable[n.Table.Name] = stmtLine
+ }
+ case *ast.AlterTableStmt:
+ if n.Table == nil {
+ continue
+ }
+ tableName := n.Table.Name
+ for _, cmd := range n.Commands {
+ if cmd == nil {
+ continue
+ }
+ switch cmd.Type {
+ case ast.ATAddColumn:
+ if slices.ContainsFunc(addColumnTargets(cmd), omniColumnCreatesIndex) {
+ lineForTable[tableName] = stmtLine
+ }
+ case ast.ATAddConstraint, ast.ATAddIndex:
+ // Cumulative #17 sibling-parity convention: dual
+ // arm preserved for forward-compat per established
+ // pattern in utils.go collectIndexFamilyAlterTable.
+ if omniConstraintCreatesIndex(cmd.Constraint) {
+ lineForTable[tableName] = stmtLine
+ }
+ case ast.ATChangeColumn, ast.ATModifyColumn:
+ if omniColumnCreatesIndex(cmd.Column) {
+ lineForTable[tableName] = stmtLine
+ }
+ default:
+ }
+ }
+ default:
+ }
}
- return checker.generateAdvice(), nil
-}
-
-type indexTotalNumberLimitChecker struct {
- adviceList []*storepb.Advice
- level storepb.Advice_Status
- title string
- text string
- line int
- max int
- lineForTable map[string]int
- finalMetadata *model.DatabaseMetadata
-}
-
-func (checker *indexTotalNumberLimitChecker) generateAdvice() []*storepb.Advice {
- type tableName struct {
+ type tableEntry struct {
name string
line int
}
- var tableList []tableName
-
- for k, v := range checker.lineForTable {
- tableList = append(tableList, tableName{
- name: k,
- line: v,
- })
+ tableList := make([]tableEntry, 0, len(lineForTable))
+ for name, line := range lineForTable {
+ tableList = append(tableList, tableEntry{name: name, line: line})
}
- slices.SortFunc(tableList, func(i, j tableName) int {
- if i.line < j.line {
+ slices.SortFunc(tableList, func(i, j tableEntry) int {
+ switch {
+ case i.line < j.line:
return -1
- }
- if i.line > j.line {
+ case i.line > j.line:
return 1
+ default:
+ return 0
}
- return 0
})
- for _, table := range tableList {
- schema := checker.finalMetadata.GetSchemaMetadata("")
+ var adviceList []*storepb.Advice
+ for _, t := range tableList {
+ schema := checkCtx.FinalMetadata.GetSchemaMetadata("")
if schema == nil {
continue
}
- tableInfo := schema.GetTable(table.name)
- if tableInfo != nil && len(tableInfo.GetProto().Indexes) > checker.max {
- checker.adviceList = append(checker.adviceList, &storepb.Advice{
- Status: checker.level,
+ tableInfo := schema.GetTable(t.name)
+ if tableInfo == nil {
+ continue
+ }
+ if count := len(tableInfo.GetProto().Indexes); count > maximum {
+ adviceList = append(adviceList, &storepb.Advice{
+ Status: level,
Code: code.IndexCountExceedsLimit.Int32(),
- Title: checker.title,
- Content: fmt.Sprintf("The count of index in table `%s` should be no more than %d, but found %d", table.name, checker.max, len(tableInfo.GetProto().Indexes)),
- StartPosition: common.ConvertANTLRLineToPosition(table.line),
+ Title: title,
+ Content: fmt.Sprintf("The count of index in table `%s` should be no more than %d, but found %d", t.name, maximum, count),
+ StartPosition: common.ConvertANTLRLineToPosition(t.line),
})
}
}
-
- return checker.adviceList
+ return adviceList, nil
}
-// Enter implements the ast.Visitor interface.
-func (checker *indexTotalNumberLimitChecker) Enter(in ast.Node) (ast.Node, bool) {
- switch node := in.(type) {
- case *ast.CreateTableStmt:
- checker.lineForTable[node.Table.Name.O] = node.OriginTextPosition()
- case *ast.AlterTableStmt:
- for _, spec := range node.Specs {
- switch spec.Tp {
- case ast.AlterTableAddColumns:
- for _, column := range spec.NewColumns {
- if createIndex(column) {
- checker.lineForTable[node.Table.Name.O] = node.OriginTextPosition()
- break
- }
- }
- case ast.AlterTableAddConstraint:
- if createIndex(spec.Constraint) {
- checker.lineForTable[node.Table.Name.O] = node.OriginTextPosition()
- }
- case ast.AlterTableChangeColumn, ast.AlterTableModifyColumn:
- if createIndex(spec.NewColumns[0]) {
- checker.lineForTable[node.Table.Name.O] = node.OriginTextPosition()
- }
- default:
- }
- }
- case *ast.CreateIndexStmt:
- checker.lineForTable[node.Table.Name.O] = node.OriginTextPosition()
+// omniConstraintCreatesIndex reports whether the given table-level
+// constraint declares a new index. Mirrors pre-omni `createIndex(*ast.Constraint)`:
+// PRIMARY KEY / UNIQUE (all 3 pingcap variants unified to ConstrUnique)
+// / KEY+INDEX (both unified to ConstrIndex) / FULLTEXT KEY are
+// index-creating. FOREIGN KEY and CHECK are NOT (pre-omni explicitly
+// excluded). SPATIAL was also NOT in pre-omni's list — preserved.
+func omniConstraintCreatesIndex(c *ast.Constraint) bool {
+ if c == nil {
+ return false
+ }
+ switch c.Type {
+ case ast.ConstrPrimaryKey, ast.ConstrUnique, ast.ConstrIndex, ast.ConstrFulltextIndex:
+ return true
default:
+ return false
}
-
- return in, false
-}
-
-// Leave implements the ast.Visitor interface.
-func (*indexTotalNumberLimitChecker) Leave(in ast.Node) (ast.Node, bool) {
- return in, true
}
-func createIndex(in ast.Node) bool {
- switch node := in.(type) {
- case *ast.ColumnDef:
- for _, option := range node.Options {
- switch option.Tp {
- case ast.ColumnOptionPrimaryKey, ast.ColumnOptionUniqKey:
- return true
- default:
- }
+// omniColumnCreatesIndex reports whether the given column definition
+// declares an inline PRIMARY KEY or UNIQUE constraint, which creates
+// an index implicitly. Mirrors pre-omni's `createIndex(*ast.ColumnDef)`
+// arm checking `ColumnOptionPrimaryKey` / `ColumnOptionUniqKey`. Omni
+// represents column-level constraints as `column.Constraints
+// []*ColumnConstraint` with `ColConstrPrimaryKey` / `ColConstrUnique`
+// type values (verified empirically against parsenodes.go:404-412).
+func omniColumnCreatesIndex(col *ast.ColumnDef) bool {
+ if col == nil {
+ return false
+ }
+ for _, c := range col.Constraints {
+ if c == nil {
+ continue
}
- case *ast.Constraint:
- switch node.Tp {
- case ast.ConstraintPrimaryKey,
- ast.ConstraintUniq,
- ast.ConstraintUniqKey,
- ast.ConstraintUniqIndex,
- ast.ConstraintKey,
- ast.ConstraintIndex,
- ast.ConstraintFulltext:
+ if c.Type == ast.ColConstrPrimaryKey || c.Type == ast.ColConstrUnique {
return true
- default:
}
- default:
}
return false
}
diff --git a/backend/plugin/advisor/tidb/test/index_key_number_limit.yaml b/backend/plugin/advisor/tidb/test/index_key_number_limit.yaml
index e5ef57e976..440a2ea920 100644
--- a/backend/plugin/advisor/tidb/test/index_key_number_limit.yaml
+++ b/backend/plugin/advisor/tidb/test/index_key_number_limit.yaml
@@ -1,5 +1,11 @@
- statement: CREATE TABLE t(a int, b int, primary key (a, b))
changeType: 1
+# Cumulative #28: pingcap-tidb accepted `PRIMARY KEY pk (cols)` (non-
+# standard extension) and captured "pk" as the constraint name. Omni
+# follows standard MySQL grammar and silently drops the index_name on
+# PRIMARY KEY (it's not in the standard syntax). The advisor falls
+# back to "PRIMARY" (MySQL canonical name) when c.Name is empty for
+# ConstrPrimaryKey — better UX than empty backticks.
- statement: |-
CREATE TABLE t(
a int,
@@ -10,7 +16,7 @@
- status: 2
code: 802
title: INDEX_KEY_NUMBER_LIMIT
- content: The number of index `pk` in table `t` should be not greater than 5
+ content: The number of index `PRIMARY` in table `t` should be not greater than 5
startposition:
line: 4
column: 0
@@ -54,3 +60,23 @@
line: 2
column: 0
endposition: null
+# Cumulative #2 unique-trio coverage pin: pingcap had ConstraintUniq /
+# ConstraintUniqKey / ConstraintUniqIndex as 3 distinct enums; omni
+# unifies all 3 under ConstrUnique (verified empirically: parsing
+# UNIQUE(...) / UNIQUE KEY n(...) / UNIQUE INDEX n(...) all yields
+# Type=ConstrUnique). The single-arm omni port covers all 3 forms
+# mechanically. UNIQUE INDEX form here exercises the third variant
+# that earlier fixtures didn't directly pin.
+- statement: |-
+ CREATE TABLE t(a int, b int, c int, d int, e int, f int, g int,
+ UNIQUE INDEX ui_all (a, b, c, d, e, f, g))
+ changeType: 1
+ want:
+ - status: 2
+ code: 802
+ title: INDEX_KEY_NUMBER_LIMIT
+ content: The number of index `ui_all` in table `t` should be not greater than 5
+ startposition:
+ line: 2
+ column: 0
+ endposition: null
diff --git a/backend/plugin/advisor/tidb/test/index_total_number_limit.yaml b/backend/plugin/advisor/tidb/test/index_total_number_limit.yaml
index 1006c21f6c..b9174ed664 100644
--- a/backend/plugin/advisor/tidb/test/index_total_number_limit.yaml
+++ b/backend/plugin/advisor/tidb/test/index_total_number_limit.yaml
@@ -55,3 +55,22 @@
line: 1
column: 0
endposition: null
+# Batch 17: ALTER TABLE ADD UNIQUE KEY pin — exercises ATAddConstraint
+# arm with omni ConstrUnique (cumulative #2 unified). tech_book has 1
+# index in mock catalog; adding 1 unique key touches lineForTable[t];
+# FinalMetadata is consulted for total count. Whether this fires
+# depends on FinalMetadata's count (set by test scaffolding). This
+# pin documents the touch path even if the catalog count doesn't
+# exceed maximum in the default mock — purpose is to verify the
+# ATAddConstraint arm registers the table touch correctly without
+# panic / crash on omni's unified ConstrUnique enum.
+- statement: ALTER TABLE tech_book ADD UNIQUE KEY uk_id (id)
+ changeType: 1
+# Batch 17: ALTER TABLE ADD COLUMN with inline PRIMARY KEY pin —
+# exercises the ATAddColumn arm's omniColumnCreatesIndex check on
+# column.Constraints[*].Type==ColConstrPrimaryKey. Cumulative #2
+# vicinity: pre-omni used ColumnOptionPrimaryKey on the column's
+# Options list; omni represents this on column.Constraints (typed
+# list with ColConstrPrimaryKey).
+- statement: ALTER TABLE tech_book ADD COLUMN new_pk int PRIMARY KEY
+ changeType: 1