MCPcopy Index your code
hub / github.com/bytebase/bytebase / DropMaterializedViewIndex

Method DropMaterializedViewIndex

backend/store/model/database.go:750–779  ·  view source on GitHub ↗

DropMaterializedViewIndex drops an index from a materialized view.

(viewName, indexName string)

Source from the content-addressed store, hash-verified

748
749// DropMaterializedViewIndex drops an index from a materialized view.
750func (s *SchemaMetadata) DropMaterializedViewIndex(viewName, indexName string) error {
751 mv := s.GetMaterializedView(viewName)
752 if mv == nil {
753 return errors.Errorf("materialized view %q does not exist in schema %q", viewName, s.proto.Name)
754 }
755
756 // Remove from indexes
757 newIndexes := make([]*storepb.IndexMetadata, 0, len(mv.Indexes))
758 found := false
759 for _, idx := range mv.Indexes {
760 if s.isObjectCaseSensitive {
761 if idx.Name != indexName {
762 newIndexes = append(newIndexes, idx)
763 } else {
764 found = true
765 }
766 } else {
767 if !strings.EqualFold(idx.Name, indexName) {
768 newIndexes = append(newIndexes, idx)
769 } else {
770 found = true
771 }
772 }
773 }
774 if !found {
775 return errors.Errorf("index %q does not exist on materialized view %q", indexName, viewName)
776 }
777 mv.Indexes = newIndexes
778 return nil
779}
780
781// GetDependentViews returns all views that depend on the given table and column.
782// This is used to check if a column can be dropped or if a table can be dropped.

Callers

nothing calls this directly

Calls 2

GetMaterializedViewMethod · 0.95
ErrorfMethod · 0.80

Tested by

no test coverage detected