Skip to content

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

refactor: simplify catalog state API by removing Find structs (#18097)

Danny Xu0cdb89ed60e7
diff --git a/backend/plugin/advisor/catalog/state.go b/backend/plugin/advisor/catalog/state.go
index a2f8d8e459..64512c7b8d 100644
--- a/backend/plugin/advisor/catalog/state.go
+++ b/backend/plugin/advisor/catalog/state.go
@@ -162,18 +162,13 @@ type DatabaseState struct {
usable bool
}
-type TableIndexFind struct {
- SchemaName string
- TableName string
-}
-
// Index returns the index map of the table.
-func (d *DatabaseState) Index(tableIndexFind *TableIndexFind) *IndexStateMap {
- schema, exists := d.schemaSet[tableIndexFind.SchemaName]
+func (d *DatabaseState) Index(schemaName string, tableName string) *IndexStateMap {
+ schema, exists := d.schemaSet[schemaName]
if !exists {
return nil
}
- return schema.Index(tableIndexFind)
+ return schema.Index(tableName)
}
// Usable returns the usable of the database state.
@@ -202,18 +197,11 @@ func (d *DatabaseState) DatabaseName() string {
return d.name
}
-// IndexFind is for find index.
-type IndexFind struct {
- SchemaName string
- TableName string
- IndexName string
-}
-
-// FindIndex finds the index.
-func (d *DatabaseState) FindIndex(find *IndexFind) (string, *IndexState) {
+// GetIndex gets the index.
+func (d *DatabaseState) GetIndex(schemaName string, tableName string, indexName string) (string, *IndexState) {
switch d.dbType {
case storepb.Engine_MYSQL, storepb.Engine_TIDB, storepb.Engine_MARIADB, storepb.Engine_OCEANBASE:
- find.IndexName = strings.ToLower(find.IndexName)
+ indexName = strings.ToLower(indexName)
default:
// For other engine types, keep the original index name without normalization
}
@@ -223,29 +211,29 @@ func (d *DatabaseState) FindIndex(find *IndexFind) (string, *IndexState) {
// In PostgreSQL, the index name is unique in a schema, not a table.
// In MySQL and TiDB, the index name is unique in a table.
// So for case one, we need match table name, but for case two, we don't need.
- needMatchTable := (d.dbType != storepb.Engine_POSTGRES || find.SchemaName == "" || find.TableName != "")
+ needMatchTable := (d.dbType != storepb.Engine_POSTGRES || schemaName == "" || tableName != "")
if needMatchTable {
- schema, exists := d.schemaSet[find.SchemaName]
+ schema, exists := d.schemaSet[schemaName]
if !exists {
return "", nil
}
- table, exists := schema.getTable(find.TableName)
+ table, exists := schema.getTable(tableName)
if !exists {
return "", nil
}
- index, exists := table.indexSet[find.IndexName]
+ index, exists := table.indexSet[indexName]
if !exists {
return "", nil
}
return table.name, index
}
for _, schema := range d.schemaSet {
- if schema.name != find.SchemaName {
+ if schema.name != schemaName {
continue
}
for _, table := range schema.tableSet {
// no need to further match table name because index is already unique in the schema
- index, exists := table.indexSet[find.IndexName]
+ index, exists := table.indexSet[indexName]
if !exists {
return "", nil
}
@@ -255,20 +243,14 @@ func (d *DatabaseState) FindIndex(find *IndexFind) (string, *IndexState) {
return "", nil
}
-// PrimaryKeyFind is for finding primary key.
-type PrimaryKeyFind struct {
- SchemaName string
- TableName string
-}
-
-// FindPrimaryKey finds the primary key.
-func (d *DatabaseState) FindPrimaryKey(find *PrimaryKeyFind) *IndexState {
+// GetPrimaryKey gets the primary key.
+func (d *DatabaseState) GetPrimaryKey(schemaName string, tableName string) *IndexState {
for _, schema := range d.schemaSet {
- if schema.name != find.SchemaName {
+ if schema.name != schemaName {
continue
}
for _, table := range schema.tableSet {
- if !compareIdentifier(table.name, find.TableName, schema.ctx.IgnoreCaseSensitive) {
+ if !compareIdentifier(table.name, tableName, schema.ctx.IgnoreCaseSensitive) {
continue
}
for _, index := range table.indexSet {
@@ -282,79 +264,59 @@ func (d *DatabaseState) FindPrimaryKey(find *PrimaryKeyFind) *IndexState {
}
// HasPrimaryKey checks if a table has a primary key.
-func (d *DatabaseState) HasPrimaryKey(find *PrimaryKeyFind) bool {
- return d.FindPrimaryKey(find) != nil
-}
-
-// ColumnCount is for counting columns.
-type ColumnCount struct {
- SchemaName string
- TableName string
- ColumnType string
+func (d *DatabaseState) HasPrimaryKey(schemaName string, tableName string) bool {
+ return d.GetPrimaryKey(schemaName, tableName) != nil
}
// CountColumn counts columns.
-func (d *DatabaseState) CountColumn(count *ColumnCount) int {
- schema, exists := d.schemaSet[count.SchemaName]
+func (d *DatabaseState) CountColumn(schemaName string, tableName string, columnType string) int {
+ schema, exists := d.schemaSet[schemaName]
if !exists {
return 0
}
- table, exists := schema.getTable(count.TableName)
+ table, exists := schema.getTable(tableName)
if !exists {
return 0
}
res := 0
for _, column := range table.columnSet {
- if column.columnType != nil && strings.EqualFold(*column.columnType, count.ColumnType) {
+ if column.columnType != nil && strings.EqualFold(*column.columnType, columnType) {
res++
}
}
return res
}
-// ColumnFind is for finding column.
-type ColumnFind struct {
- SchemaName string
- TableName string
- ColumnName string
-}
-
-// FindColumn finds the column.
-func (d *DatabaseState) FindColumn(find *ColumnFind) *ColumnState {
+// GetColumn gets the column.
+func (d *DatabaseState) GetColumn(schemaName string, tableName string, columnName string) *ColumnState {
switch d.dbType {
case storepb.Engine_MYSQL, storepb.Engine_TIDB, storepb.Engine_MARIADB, storepb.Engine_OCEANBASE:
- find.ColumnName = strings.ToLower(find.ColumnName)
+ columnName = strings.ToLower(columnName)
default:
// For other engine types, keep the original column name without normalization
}
- schema, exists := d.schemaSet[find.SchemaName]
+ schema, exists := d.schemaSet[schemaName]
if !exists {
return nil
}
- table, exists := schema.getTable(find.TableName)
+ table, exists := schema.getTable(tableName)
if !exists {
return nil
}
- column, exists := table.columnSet[find.ColumnName]
+ column, exists := table.columnSet[columnName]
if !exists {
return nil
}
return column
}
-// TableFind is for find table.
-type TableFind struct {
- SchemaName string
- TableName string
-}
-
-// FindTable finds the table.
-func (d *DatabaseState) FindTable(find *TableFind) *TableState {
- schema, exists := d.schemaSet[find.SchemaName]
+// GetTable gets the table.
+func (d *DatabaseState) GetTable(schemaName string, tableName string) *TableState {
+ schema, exists := d.schemaSet[schemaName]
if !exists {
return nil
}
- table, exists := schema.getTable(find.TableName)
+ table, exists := schema.getTable(tableName)
if !exists {
return nil
}
@@ -375,12 +337,12 @@ type SchemaState struct {
identifierMap identifierMap
}
-func (s *SchemaState) Index(tableIndexFind *TableIndexFind) *IndexStateMap {
- table, exists := s.getTable(tableIndexFind.TableName)
+func (s *SchemaState) Index(tableName string) *IndexStateMap {
+ table, exists := s.getTable(tableName)
if !exists {
return nil
}
- return table.Index(tableIndexFind)
+ return table.Index()
}
type schemaStateMap map[string]*SchemaState
@@ -418,7 +380,7 @@ func (t *TableState) CountIndex() int {
}
// Index return the index map of table.
-func (t *TableState) Index(_ *TableIndexFind) *IndexStateMap {
+func (t *TableState) Index() *IndexStateMap {
return &t.indexSet
}
diff --git a/backend/plugin/advisor/mysql/rule_column_disallow_changing_type.go b/backend/plugin/advisor/mysql/rule_column_disallow_changing_type.go
index 91af8fe39b..7981327756 100644
--- a/backend/plugin/advisor/mysql/rule_column_disallow_changing_type.go
+++ b/backend/plugin/advisor/mysql/rule_column_disallow_changing_type.go
@@ -168,10 +168,7 @@ func normalizeColumnType(tp string) string {
func (r *ColumnDisallowChangingTypeRule) changeColumnType(tableName, columnName string, dataType mysql.IDataTypeContext) {
tp := dataType.GetParser().GetTokenStream().GetTextFromRuleContext(dataType)
- column := r.catalog.Origin.FindColumn(&catalog.ColumnFind{
- TableName: tableName,
- ColumnName: columnName,
- })
+ column := r.catalog.Origin.GetColumn("", tableName, columnName)
if column == nil {
return
diff --git a/backend/plugin/advisor/mysql/rule_column_disallow_drop_in_index.go b/backend/plugin/advisor/mysql/rule_column_disallow_drop_in_index.go
index c55387417f..e8730476c4 100644
--- a/backend/plugin/advisor/mysql/rule_column_disallow_drop_in_index.go
+++ b/backend/plugin/advisor/mysql/rule_column_disallow_drop_in_index.go
@@ -156,11 +156,7 @@ func (r *ColumnDisallowDropInIndexRule) checkAlterTable(ctx *mysql.AlterTableCon
continue
}
- index := r.catalog.Origin.Index(&catalog.TableIndexFind{
- // In MySQL, the SchemaName is "".
- SchemaName: "",
- TableName: tableName,
- })
+ index := r.catalog.Origin.Index("", tableName)
if index != nil {
if r.tables[tableName] == nil {
diff --git a/backend/plugin/advisor/mysql/rule_column_no_null.go b/backend/plugin/advisor/mysql/rule_column_no_null.go
index 7aa05f6786..ae4c2e089c 100644
--- a/backend/plugin/advisor/mysql/rule_column_no_null.go
+++ b/backend/plugin/advisor/mysql/rule_column_no_null.go
@@ -134,10 +134,7 @@ func (r *ColumnNoNullRule) generateAdvice() {
})
for _, column := range columnList {
- col := r.catalog.Final.FindColumn(&catalog.ColumnFind{
- TableName: column.tableName,
- ColumnName: column.columnName,
- })
+ col := r.catalog.Final.GetColumn("", column.tableName, column.columnName)
if col != nil && col.Nullable() {
r.AddAdvice(&storepb.Advice{
Status: r.level,
diff --git a/backend/plugin/advisor/mysql/rule_index_pk_type.go b/backend/plugin/advisor/mysql/rule_index_pk_type.go
index af656f9dcb..573369a855 100644
--- a/backend/plugin/advisor/mysql/rule_index_pk_type.go
+++ b/backend/plugin/advisor/mysql/rule_index_pk_type.go
@@ -236,10 +236,7 @@ func (r *IndexPkTypeRule) getPKColumnType(tableName string, columnName string) (
if columnType, ok := r.tablesNewColumns.get(tableName, columnName); ok {
return columnType, nil
}
- column := r.catalog.Origin.FindColumn(&catalog.ColumnFind{
- TableName: tableName,
- ColumnName: columnName,
- })
+ column := r.catalog.Origin.GetColumn("", tableName, columnName)
if column != nil {
return column.Type(), nil
}
diff --git a/backend/plugin/advisor/mysql/rule_index_primary_key_type_allowlist.go b/backend/plugin/advisor/mysql/rule_index_primary_key_type_allowlist.go
index c1c722f0b4..887861956c 100644
--- a/backend/plugin/advisor/mysql/rule_index_primary_key_type_allowlist.go
+++ b/backend/plugin/advisor/mysql/rule_index_primary_key_type_allowlist.go
@@ -250,10 +250,7 @@ func (r *IndexPrimaryKeyTypeAllowlistRule) getPKColumnType(tableName string, col
if columnType, ok := r.tablesNewColumns.get(tableName, columnName); ok {
return columnType, nil
}
- column := r.catalog.Origin.FindColumn(&catalog.ColumnFind{
- TableName: tableName,
- ColumnName: columnName,
- })
+ column := r.catalog.Origin.GetColumn("", tableName, columnName)
if column != nil {
return column.Type(), nil
}
diff --git a/backend/plugin/advisor/mysql/rule_index_total_number_limit.go b/backend/plugin/advisor/mysql/rule_index_total_number_limit.go
index 09465e59d2..841d4c5aed 100644
--- a/backend/plugin/advisor/mysql/rule_index_total_number_limit.go
+++ b/backend/plugin/advisor/mysql/rule_index_total_number_limit.go
@@ -130,7 +130,7 @@ func (r *IndexTotalNumberLimitRule) generateAdvice() []*storepb.Advice {
})
for _, table := range tableList {
- tableInfo := r.catalog.Final.FindTable(&catalog.TableFind{TableName: table.name})
+ tableInfo := r.catalog.Final.GetTable("", table.name)
if tableInfo != nil && tableInfo.CountIndex() > r.max {
r.AddAdvice(&storepb.Advice{
Status: r.level,
diff --git a/backend/plugin/advisor/mysql/rule_index_type_no_blob.go b/backend/plugin/advisor/mysql/rule_index_type_no_blob.go
index dd89692ea1..140d0719fd 100644
--- a/backend/plugin/advisor/mysql/rule_index_type_no_blob.go
+++ b/backend/plugin/advisor/mysql/rule_index_type_no_blob.go
@@ -293,10 +293,7 @@ func (r *IndexTypeNoBlobRule) getColumnType(tableName string, columnName string)
if columnType, ok := r.tablesNewColumns.get(tableName, columnName); ok {
return columnType, nil
}
- column := r.catalog.Origin.FindColumn(&catalog.ColumnFind{
- TableName: tableName,
- ColumnName: columnName,
- })
+ column := r.catalog.Origin.GetColumn("", tableName, columnName)
if column != nil {
return column.Type(), nil
}
diff --git a/backend/plugin/advisor/mysql/rule_naming_index_convention.go b/backend/plugin/advisor/mysql/rule_naming_index_convention.go
index 45cd91d89f..0ab456da3f 100644
--- a/backend/plugin/advisor/mysql/rule_naming_index_convention.go
+++ b/backend/plugin/advisor/mysql/rule_naming_index_convention.go
@@ -186,10 +186,7 @@ func (r *NamingIndexConventionRule) checkAlterTable(ctx *mysql.AlterTableContext
case alterListItem.RENAME_SYMBOL() != nil && alterListItem.KeyOrIndex() != nil && alterListItem.IndexRef() != nil && alterListItem.IndexName() != nil:
_, _, oldIndexName := mysqlparser.NormalizeIndexRef(alterListItem.IndexRef())
newIndexName := mysqlparser.NormalizeIndexName(alterListItem.IndexName())
- _, indexState := r.catalog.Origin.FindIndex(&catalog.IndexFind{
- TableName: tableName,
- IndexName: oldIndexName,
- })
+ _, indexState := r.catalog.Origin.GetIndex("", tableName, oldIndexName)
if indexState == nil {
continue
}
diff --git a/backend/plugin/advisor/mysql/rule_naming_unique_key_convention.go b/backend/plugin/advisor/mysql/rule_naming_unique_key_convention.go
index 24ec216ae7..e2bc465194 100644
--- a/backend/plugin/advisor/mysql/rule_naming_unique_key_convention.go
+++ b/backend/plugin/advisor/mysql/rule_naming_unique_key_convention.go
@@ -187,10 +187,7 @@ func (r *NamingUKConventionRule) checkAlterTable(ctx *mysql.AlterTableContext) {
case alterListItem.RENAME_SYMBOL() != nil && alterListItem.KeyOrIndex() != nil && alterListItem.IndexRef() != nil && alterListItem.IndexName() != nil:
_, _, oldIndexName := mysqlparser.NormalizeIndexRef(alterListItem.IndexRef())
newIndexName := mysqlparser.NormalizeIndexName(alterListItem.IndexName())
- indexStateMap := r.catalog.Origin.Index(&catalog.TableIndexFind{
- SchemaName: "",
- TableName: tableName,
- })
+ indexStateMap := r.catalog.Origin.Index("", tableName)
if indexStateMap == nil {
continue
}
diff --git a/backend/plugin/advisor/mysql/rule_table_require_pk.go b/backend/plugin/advisor/mysql/rule_table_require_pk.go
index e29754c8ca..136aebb922 100644
--- a/backend/plugin/advisor/mysql/rule_table_require_pk.go
+++ b/backend/plugin/advisor/mysql/rule_table_require_pk.go
@@ -250,10 +250,7 @@ func (r *TableRequirePKRule) changeColumn(tableName string, oldColumn string, ne
func (r *TableRequirePKRule) dropColumn(tableName string, columnName string) bool {
if _, ok := r.tables[tableName]; !ok {
- _, pk := r.catalog.Origin.FindIndex(&catalog.IndexFind{
- TableName: tableName,
- IndexName: primaryKeyName,
- })
+ _, pk := r.catalog.Origin.GetIndex("", tableName, primaryKeyName)
if pk == nil {
return false
}
diff --git a/backend/plugin/advisor/mysql/rule_table_text_fields_total_length.go b/backend/plugin/advisor/mysql/rule_table_text_fields_total_length.go
index 79c2badcb0..00a9177911 100644
--- a/backend/plugin/advisor/mysql/rule_table_text_fields_total_length.go
+++ b/backend/plugin/advisor/mysql/rule_table_text_fields_total_length.go
@@ -114,7 +114,7 @@ func (r *TableTextFieldsTotalLengthRule) checkCreateTable(ctx *mysql.CreateTable
if tableName == "" {
return
}
- tableInfo := r.catalog.Final.FindTable(&catalog.TableFind{TableName: tableName})
+ tableInfo := r.catalog.Final.GetTable("", tableName)
if tableInfo == nil {
return
}
@@ -148,7 +148,7 @@ func (r *TableTextFieldsTotalLengthRule) checkAlterTable(ctx *mysql.AlterTableCo
if tableName == "" {
return
}
- tableInfo := r.catalog.Final.FindTable(&catalog.TableFind{TableName: tableName})
+ tableInfo := r.catalog.Final.GetTable("", tableName)
if tableInfo == nil {
return
}
diff --git a/backend/plugin/advisor/pg/advisor_column_no_null.go b/backend/plugin/advisor/pg/advisor_column_no_null.go
index fd02f60a9f..956ed66539 100644
--- a/backend/plugin/advisor/pg/advisor_column_no_null.go
+++ b/backend/plugin/advisor/pg/advisor_column_no_null.go
@@ -307,11 +307,7 @@ func (r *columnNoNullRule) removeColumnByTableConstraint(schema, table string, c
indexName := pg.NormalizePostgreSQLName(existingIndex.Name())
// Try to find index in catalog
if r.catalog != nil {
- _, index := r.catalog.Origin.FindIndex(&catalog.IndexFind{
- SchemaName: schema,
- TableName: table,
- IndexName: indexName,
- })
+ _, index := r.catalog.Origin.GetIndex(schema, table, indexName)
if index != nil {
for _, expression := range index.ExpressionList() {
r.removeColumn(schema, table, expression)
diff --git a/backend/plugin/advisor/pg/advisor_index_total_number_limit.go b/backend/plugin/advisor/pg/advisor_index_total_number_limit.go
index f5b4900a17..8b63796f39 100644
--- a/backend/plugin/advisor/pg/advisor_index_total_number_limit.go
+++ b/backend/plugin/advisor/pg/advisor_index_total_number_limit.go
@@ -124,10 +124,7 @@ func (r *indexTotalNumberLimitRule) generateAdvice() {
})
for _, table := range tableList {
- tableInfo := r.catalog.Final.FindTable(&catalog.TableFind{
- SchemaName: table.schema,
- TableName: table.table,
- })
+ tableInfo := r.catalog.Final.GetTable(table.schema, table.table)
if tableInfo != nil && tableInfo.CountIndex() > r.max {
r.AddAdvice(&storepb.Advice{
Status: r.level,
diff --git a/backend/plugin/advisor/pg/advisor_naming_index_convention.go b/backend/plugin/advisor/pg/advisor_naming_index_convention.go
index f4e0d66873..4563ff9325 100644
--- a/backend/plugin/advisor/pg/advisor_naming_index_convention.go
+++ b/backend/plugin/advisor/pg/advisor_naming_index_convention.go
@@ -236,9 +236,5 @@ func (r *namingIndexConventionRule) findIndex(schemaName string, tableName strin
if r.catalog == nil {
return "", nil
}
- return r.catalog.Origin.FindIndex(&catalog.IndexFind{
- SchemaName: normalizeSchemaName(schemaName),
- TableName: tableName,
- IndexName: indexName,
- })
+ return r.catalog.Origin.GetIndex(normalizeSchemaName(schemaName), tableName, indexName)
}
diff --git a/backend/plugin/advisor/pg/advisor_naming_primary_key_convention.go b/backend/plugin/advisor/pg/advisor_naming_primary_key_convention.go
index d1c840f280..02cb462229 100644
--- a/backend/plugin/advisor/pg/advisor_naming_primary_key_convention.go
+++ b/backend/plugin/advisor/pg/advisor_naming_primary_key_convention.go
@@ -195,11 +195,7 @@ func (r *namingPKConventionRule) handleRenamestmt(ctx *parser.RenamestmtContext)
if normalizedSchema == "" {
normalizedSchema = "public"
}
- _, index := r.catalog.Origin.FindIndex(&catalog.IndexFind{
- SchemaName: normalizedSchema,
- TableName: tableName,
- IndexName: oldName,
- })
+ _, index := r.catalog.Origin.GetIndex(normalizedSchema, tableName, oldName)
if index != nil && index.Primary() {
metaData := map[string]string{
advisor.ColumnListTemplateToken: strings.Join(index.ExpressionList(), "_"),
@@ -243,11 +239,8 @@ func (r *namingPKConventionRule) handleRenamestmt(ctx *parser.RenamestmtContext)
normalizedSchema = "public"
}
// "ALTER INDEX name RENAME TO new_name" doesn't specify table name
- tableName, index := r.catalog.Origin.FindIndex(&catalog.IndexFind{
- SchemaName: normalizedSchema,
- TableName: "", // Empty table name for ALTER INDEX
- IndexName: oldIndexName,
- })
+ // Empty table name for ALTER INDEX
+ tableName, index := r.catalog.Origin.GetIndex(normalizedSchema, "", oldIndexName)
if index != nil && index.Primary() {
metaData := map[string]string{
advisor.ColumnListTemplateToken: strings.Join(index.ExpressionList(), "_"),
@@ -318,11 +311,7 @@ func (r *namingPKConventionRule) getPKMetaDataFromTableConstraint(constraint par
if normalizedSchema == "" {
normalizedSchema = "public"
}
- _, index := r.catalog.Origin.FindIndex(&catalog.IndexFind{
- SchemaName: normalizedSchema,
- TableName: tableName,
- IndexName: indexName,
- })
+ _, index := r.catalog.Origin.GetIndex(normalizedSchema, tableName, indexName)
if index != nil {
columnList = index.ExpressionList()
}
diff --git a/backend/plugin/advisor/pg/advisor_naming_unique_key_convention.go b/backend/plugin/advisor/pg/advisor_naming_unique_key_convention.go
index b75861d7dc..fe62b6a8a7 100644
--- a/backend/plugin/advisor/pg/advisor_naming_unique_key_convention.go
+++ b/backend/plugin/advisor/pg/advisor_naming_unique_key_convention.go
@@ -410,9 +410,5 @@ func (r *namingUKConventionRule) findIndex(schemaName string, tableName string,
if r.catalog == nil {
return "", nil
}
- return r.catalog.Origin.FindIndex(&catalog.IndexFind{
- SchemaName: normalizeSchemaName(schemaName),
- TableName: tableName,
- IndexName: indexName,
- })
+ return r.catalog.Origin.GetIndex(normalizeSchemaName(schemaName), tableName, indexName)
}
diff --git a/backend/plugin/advisor/pg/advisor_table_require_pk.go b/backend/plugin/advisor/pg/advisor_table_require_pk.go
index 7bca05a484..4e91165fd7 100644
--- a/backend/plugin/advisor/pg/advisor_table_require_pk.go
+++ b/backend/plugin/advisor/pg/advisor_table_require_pk.go
@@ -179,10 +179,7 @@ func (r *tableRequirePKRule) validateFinalState() {
schemaName, tableName := parseTableKey(tableKey)
// Check catalog.Final for PRIMARY KEY
- hasPK := r.catalog.Final.HasPrimaryKey(&catalog.PrimaryKeyFind{
- SchemaName: schemaName,
- TableName: tableName,
- })
+ hasPK := r.catalog.Final.HasPrimaryKey(schemaName, tableName)
if !hasPK {
content := fmt.Sprintf("Table %q.%q requires PRIMARY KEY", schemaName, tableName)
diff --git a/backend/plugin/advisor/tidb/advisor_column_disallow_changing_type.go b/backend/plugin/advisor/tidb/advisor_column_disallow_changing_type.go
index 9674dd8cd0..691a97d2c7 100644
--- a/backend/plugin/advisor/tidb/advisor_column_disallow_changing_type.go
+++ b/backend/plugin/advisor/tidb/advisor_column_disallow_changing_type.go
@@ -129,10 +129,7 @@ func normalizeColumnType(tp string) string {
}
func (checker *columnDisallowChangingTypeChecker) changeColumnType(tableName string, columName string, newType string) bool {
- column := checker.catalog.Origin.FindColumn(&catalog.ColumnFind{
- TableName: tableName,
- ColumnName: columName,
- })
+ column := checker.catalog.Origin.GetColumn("", tableName, columName)
if column == nil {
return false
diff --git a/backend/plugin/advisor/tidb/advisor_column_disallow_drop_in_index.go b/backend/plugin/advisor/tidb/advisor_column_disallow_drop_in_index.go
index 6b37cdb226..2e82bceb0d 100644
--- a/backend/plugin/advisor/tidb/advisor_column_disallow_drop_in_index.go
+++ b/backend/plugin/advisor/tidb/advisor_column_disallow_drop_in_index.go
@@ -86,11 +86,7 @@ func (checker *columnDisallowDropInIndexChecker) dropColumn(in ast.Node) (ast.No
if spec.Tp == ast.AlterTableDropColumn {
table := node.Table.Name.O
- index := checker.catalog.Origin.Index(&catalog.TableIndexFind{
- // In MySQL, the SchemaName is "".
- SchemaName: "",
- TableName: table,
- })
+ index := checker.catalog.Origin.Index("", table)
if index != nil {
if checker.tables[table] == nil {
diff --git a/backend/plugin/advisor/tidb/advisor_column_no_null.go b/backend/plugin/advisor/tidb/advisor_column_no_null.go
index 3c9b73f538..ff06e6e6fd 100644
--- a/backend/plugin/advisor/tidb/advisor_column_no_null.go
+++ b/backend/plugin/advisor/tidb/advisor_column_no_null.go
@@ -82,10 +82,7 @@ func (checker *columnNoNullChecker) generateAdvice() []*storepb.Advice {
})
for _, column := range columnList {
- col := checker.catalog.Final.FindColumn(&catalog.ColumnFind{
- TableName: column.tableName,
- ColumnName: column.columnName,
- })
+ col := checker.catalog.Final.GetColumn("", column.tableName, column.columnName)
if col != nil && col.Nullable() {
checker.adviceList = append(checker.adviceList, &storepb.Advice{
Status: checker.level,
diff --git a/backend/plugin/advisor/tidb/advisor_index_pk_type.go b/backend/plugin/advisor/tidb/advisor_index_pk_type.go
index 3a5e1fc259..86deca706b 100644
--- a/backend/plugin/advisor/tidb/advisor_index_pk_type.go
+++ b/backend/plugin/advisor/tidb/advisor_index_pk_type.go
@@ -218,10 +218,7 @@ func (v *indexPkTypeChecker) getPKColumnType(tableName string, columnName string
if colDef, ok := v.tablesNewColumns.get(tableName, columnName); ok {
return v.getIntOrBigIntStr(colDef.Tp), nil
}
- column := v.catalog.Origin.FindColumn(&catalog.ColumnFind{
- TableName: tableName,
- ColumnName: columnName,
- })
+ column := v.catalog.Origin.GetColumn("", tableName, columnName)
if column != nil {
return column.Type(), nil
}
diff --git a/backend/plugin/advisor/tidb/advisor_index_primary_key_type_allowlist.go b/backend/plugin/advisor/tidb/advisor_index_primary_key_type_allowlist.go
index e273584f96..75600fdb81 100644
--- a/backend/plugin/advisor/tidb/advisor_index_primary_key_type_allowlist.go
+++ b/backend/plugin/advisor/tidb/advisor_index_primary_key_type_allowlist.go
@@ -199,10 +199,7 @@ func (v *indexPrimaryKeyTypeAllowlistChecker) getPKColumnType(tableName string,
if colDef, ok := v.tablesNewColumns.get(tableName, columnName); ok {
return tidbparser.TypeString(colDef.Tp.GetType()), nil
}
- column := v.catalog.Origin.FindColumn(&catalog.ColumnFind{
- TableName: tableName,
- ColumnName: columnName,
- })
+ column := v.catalog.Origin.GetColumn("", tableName, columnName)
if column != nil {
return column.Type(), nil
}
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 3b48796d09..c1b4764e71 100644
--- a/backend/plugin/advisor/tidb/advisor_index_total_number_limit.go
+++ b/backend/plugin/advisor/tidb/advisor_index_total_number_limit.go
@@ -96,7 +96,7 @@ func (checker *indexTotalNumberLimitChecker) generateAdvice() []*storepb.Advice
})
for _, table := range tableList {
- tableInfo := checker.catalog.Final.FindTable(&catalog.TableFind{TableName: table.name})
+ tableInfo := checker.catalog.Final.GetTable("", table.name)
if tableInfo != nil && tableInfo.CountIndex() > checker.max {
checker.adviceList = append(checker.adviceList, &storepb.Advice{
Status: checker.level,
diff --git a/backend/plugin/advisor/tidb/advisor_index_type_no_blob.go b/backend/plugin/advisor/tidb/advisor_index_type_no_blob.go
index 21965b4441..d1cf0e1ae0 100644
--- a/backend/plugin/advisor/tidb/advisor_index_type_no_blob.go
+++ b/backend/plugin/advisor/tidb/advisor_index_type_no_blob.go
@@ -221,10 +221,7 @@ func (v *indexTypeNoBlobChecker) getColumnType(tableName string, columnName stri
if colDef, ok := v.tablesNewColumns.get(tableName, columnName); ok {
return v.getBlobStr(colDef.Tp), nil
}
- column := v.catalog.Origin.FindColumn(&catalog.ColumnFind{
- TableName: tableName,
- ColumnName: columnName,
- })
+ column := v.catalog.Origin.GetColumn("", tableName, columnName)
if column != nil {
return column.Type(), nil
}
diff --git a/backend/plugin/advisor/tidb/advisor_naming_index_convention.go b/backend/plugin/advisor/tidb/advisor_naming_index_convention.go
index 5258981d71..83b94c35a2 100644
--- a/backend/plugin/advisor/tidb/advisor_naming_index_convention.go
+++ b/backend/plugin/advisor/tidb/advisor_naming_index_convention.go
@@ -150,10 +150,7 @@ func (checker *namingIndexConventionChecker) getMetaDataList(in ast.Node) []*ind
for _, spec := range node.Specs {
switch spec.Tp {
case ast.AlterTableRenameIndex:
- _, index := checker.catalog.Origin.FindIndex(&catalog.IndexFind{
- TableName: node.Table.Name.String(),
- IndexName: spec.FromKey.String(),
- })
+ _, index := checker.catalog.Origin.GetIndex("", node.Table.Name.String(), spec.FromKey.String())
if index == nil {
continue
}
diff --git a/backend/plugin/advisor/tidb/advisor_naming_unique_key_convention.go b/backend/plugin/advisor/tidb/advisor_naming_unique_key_convention.go
index bf09d429f2..dc41313a00 100644
--- a/backend/plugin/advisor/tidb/advisor_naming_unique_key_convention.go
+++ b/backend/plugin/advisor/tidb/advisor_naming_unique_key_convention.go
@@ -141,10 +141,7 @@ func (checker *namingUKConventionChecker) getMetaDataList(in ast.Node) []*indexM
for _, spec := range node.Specs {
switch spec.Tp {
case ast.AlterTableRenameIndex:
- _, index := checker.catalog.Origin.FindIndex(&catalog.IndexFind{
- TableName: node.Table.Name.String(),
- IndexName: spec.FromKey.String(),
- })
+ _, index := checker.catalog.Origin.GetIndex("", node.Table.Name.String(), spec.FromKey.String())
if index == nil {
continue
}
diff --git a/backend/plugin/advisor/tidb/advisor_table_require_pk.go b/backend/plugin/advisor/tidb/advisor_table_require_pk.go
index 13cbb05558..e1e72e8b9a 100644
--- a/backend/plugin/advisor/tidb/advisor_table_require_pk.go
+++ b/backend/plugin/advisor/tidb/advisor_table_require_pk.go
@@ -179,11 +179,9 @@ func (v *tableRequirePKChecker) createTableLike(node *ast.CreateTableStmt) {
}
v.tables[table] = newColumnSet(columns)
} else {
- referTableState := v.catalog.Origin.FindTable(&catalog.TableFind{
- TableName: referTableName,
- })
+ referTableState := v.catalog.Origin.GetTable("", referTableName)
if referTableState != nil {
- indexSet := referTableState.Index(&catalog.TableIndexFind{})
+ indexSet := referTableState.Index()
for _, index := range *indexSet {
if index.Primary() {
v.tables[table] = newColumnSet(index.ExpressionList())
@@ -195,10 +193,7 @@ func (v *tableRequirePKChecker) createTableLike(node *ast.CreateTableStmt) {
func (v *tableRequirePKChecker) dropColumn(table string, column string) bool {
if _, ok := v.tables[table]; !ok {
- _, pk := v.catalog.Origin.FindIndex(&catalog.IndexFind{
- TableName: table,
- IndexName: primaryKeyName,
- })
+ _, pk := v.catalog.Origin.GetIndex("", table, primaryKeyName)
if pk == nil {
return false
}