MCPcopy Create free account
hub / github.com/bytebase/bytebase / CreateIndex

Method CreateIndex

backend/store/model/database.go:1198–1215  ·  view source on GitHub ↗

CreateIndex creates a new index in the table. Returns an error if the index already exists.

(indexProto *storepb.IndexMetadata)

Source from the content-addressed store, hash-verified

1196// CreateIndex creates a new index in the table.
1197// Returns an error if the index already exists.
1198func (t *TableMetadata) CreateIndex(indexProto *storepb.IndexMetadata) error {
1199 // Check if index already exists
1200 if t.GetIndex(indexProto.Name) != nil {
1201 return errors.Errorf("index %q already exists in table %q", indexProto.Name, t.proto.Name)
1202 }
1203
1204 // Add to proto's index list
1205 t.proto.Indexes = append(t.proto.Indexes, indexProto)
1206
1207 // Add to internal map
1208 indexID := normalizeNameByCaseSensitivity(indexProto.Name, t.isDetailCaseSensitive)
1209 t.internalIndexes[indexID] = &IndexMetadata{
1210 tableProto: t.proto,
1211 proto: indexProto,
1212 }
1213
1214 return nil
1215}
1216
1217// DropIndex drops an index from the table.
1218// Returns an error if the index does not exist.

Callers 4

tidbCopyTableFunction · 0.80
tidbCreateIndexHelperFunction · 0.80

Calls 3

GetIndexMethod · 0.95
ErrorfMethod · 0.80

Tested by 1