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

Function generateCreateIndex

backend/plugin/schema/mssql/generate_migration.go:817–895  ·  view source on GitHub ↗
(schemaName, tableName string, index *storepb.IndexMetadata)

Source from the content-addressed store, hash-verified

815}
816
817func generateCreateIndex(schemaName, tableName string, index *storepb.IndexMetadata) string {
818 var buf strings.Builder
819
820 _, _ = buf.WriteString("CREATE")
821
822 // Handle columnstore indexes specially
823 indexType := strings.ToUpper(index.Type)
824 switch indexType {
825 case "CLUSTERED COLUMNSTORE":
826 _, _ = buf.WriteString(" CLUSTERED COLUMNSTORE INDEX [")
827 _, _ = buf.WriteString(index.Name)
828 _, _ = buf.WriteString("] ON [")
829 _, _ = buf.WriteString(schemaName)
830 _, _ = buf.WriteString("].[")
831 _, _ = buf.WriteString(tableName)
832 _, _ = buf.WriteString("]")
833 // Clustered columnstore indexes don't specify columns
834 return buf.String()
835 case "NONCLUSTERED COLUMNSTORE":
836 _, _ = buf.WriteString(" NONCLUSTERED COLUMNSTORE INDEX [")
837 _, _ = buf.WriteString(index.Name)
838 _, _ = buf.WriteString("] ON [")
839 _, _ = buf.WriteString(schemaName)
840 _, _ = buf.WriteString("].[")
841 _, _ = buf.WriteString(tableName)
842 _, _ = buf.WriteString("]")
843 // Nonclustered columnstore indexes may specify columns
844 if len(index.Expressions) > 0 {
845 _, _ = buf.WriteString(" (")
846 for i, expr := range index.Expressions {
847 if i > 0 {
848 _, _ = buf.WriteString(", ")
849 }
850 _, _ = buf.WriteString("[")
851 _, _ = buf.WriteString(expr)
852 _, _ = buf.WriteString("]")
853 }
854 _, _ = buf.WriteString(")")
855 }
856 return buf.String()
857 case "SPATIAL":
858 return generateSpatialIndexDDL(index, schemaName, tableName)
859 default:
860 // Regular indexes
861 if index.Unique {
862 _, _ = buf.WriteString(" UNIQUE")
863 }
864
865 switch index.Type {
866 case "CLUSTERED":
867 _, _ = buf.WriteString(" CLUSTERED")
868 case "NONCLUSTERED":
869 _, _ = buf.WriteString(" NONCLUSTERED")
870 default:
871 // Other index types
872 }
873
874 _, _ = buf.WriteString(" INDEX [")

Callers 2

generateCreateTableFunction · 0.85
generateAlterTableFunction · 0.85

Calls 2

generateSpatialIndexDDLFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected