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

Function indexesEqual

backend/plugin/schema/differ.go:787–835  ·  view source on GitHub ↗

indexesEqual checks if two indexes are equal.

(engine storepb.Engine, idx1, idx2 *storepb.IndexMetadata)

Source from the content-addressed store, hash-verified

785
786// indexesEqual checks if two indexes are equal.
787func indexesEqual(engine storepb.Engine, idx1, idx2 *storepb.IndexMetadata) bool {
788 if idx1.Type != idx2.Type {
789 return false
790 }
791 if idx1.Unique != idx2.Unique {
792 return false
793 }
794 if idx1.Primary != idx2.Primary {
795 return false
796 }
797 if len(idx1.Expressions) != len(idx2.Expressions) {
798 return false
799 }
800 for i, expr := range idx1.Expressions {
801 if !CompareExpressionsSemantically(engine, expr, idx2.Expressions[i]) {
802 return false
803 }
804 }
805
806 // Compare key lengths
807 if len(idx1.KeyLength) != len(idx2.KeyLength) {
808 return false
809 }
810 for i, keyLen := range idx1.KeyLength {
811 if keyLen != idx2.KeyLength[i] {
812 return false
813 }
814 }
815
816 // Compare descending order - be flexible about empty arrays vs arrays of false
817 // This handles the case where one has [] and the other has [false, false, ...]
818 if !descendingArraysEqual(idx1.Descending, idx2.Descending) {
819 return false
820 }
821
822 // Compare visibility
823 if idx1.Visible != idx2.Visible {
824 return false
825 }
826
827 // Compare spatial configuration
828 if !spatialConfigsEqual(idx1.SpatialConfig, idx2.SpatialConfig) {
829 return false
830 }
831
832 // Compare WHERE conditions for partial indexes using engine-specific comparer
833 comparer := GetIndexComparer(engine)
834 return comparer.CompareIndexWhereConditions(idx1.Definition, idx2.Definition)
835}
836
837// descendingArraysEqual compares two descending arrays, considering empty arrays
838// and arrays of all false values as equivalent for constraint-based indexes.

Callers 1

compareIndexesFunction · 0.85

Calls 5

descendingArraysEqualFunction · 0.85
spatialConfigsEqualFunction · 0.85
GetIndexComparerFunction · 0.85

Tested by

no test coverage detected