CreateIndex creates a new index in the table. Returns an error if the index already exists.
(indexProto *storepb.IndexMetadata)
| 1196 | // CreateIndex creates a new index in the table. |
| 1197 | // Returns an error if the index already exists. |
| 1198 | func (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. |