DropIndex drops an index from the table. Returns an error if the index does not exist.
(indexName string)
| 1217 | // DropIndex drops an index from the table. |
| 1218 | // Returns an error if the index does not exist. |
| 1219 | func (t *TableMetadata) DropIndex(indexName string) error { |
| 1220 | // Check if index exists |
| 1221 | if t.GetIndex(indexName) == nil { |
| 1222 | return errors.Errorf("index %q does not exist in table %q", indexName, t.proto.Name) |
| 1223 | } |
| 1224 | |
| 1225 | // Remove from internal map |
| 1226 | indexID := normalizeNameByCaseSensitivity(indexName, t.isDetailCaseSensitive) |
| 1227 | delete(t.internalIndexes, indexID) |
| 1228 | |
| 1229 | // Remove from proto's index list |
| 1230 | newIndexes := make([]*storepb.IndexMetadata, 0, len(t.proto.Indexes)-1) |
| 1231 | for _, index := range t.proto.Indexes { |
| 1232 | if t.isDetailCaseSensitive { |
| 1233 | if index.Name != indexName { |
| 1234 | newIndexes = append(newIndexes, index) |
| 1235 | } |
| 1236 | } else { |
| 1237 | if !strings.EqualFold(index.Name, indexName) { |
| 1238 | newIndexes = append(newIndexes, index) |
| 1239 | } |
| 1240 | } |
| 1241 | } |
| 1242 | t.proto.Indexes = newIndexes |
| 1243 | |
| 1244 | return nil |
| 1245 | } |
| 1246 | |
| 1247 | // RenameIndex renames an index in the table. |
| 1248 | // Returns an error if the old index doesn't exist or new index already exists. |
no test coverage detected