Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: support column store index for mssql (#16280)

rebelice5adda6d3eacc
diff --git a/backend/plugin/schema/mssql/get_database_definition.go b/backend/plugin/schema/mssql/get_database_definition.go
index 42af3538b9..dff37f759e 100644
--- a/backend/plugin/schema/mssql/get_database_definition.go
+++ b/backend/plugin/schema/mssql/get_database_definition.go
@@ -83,7 +83,22 @@ func writeTable(out *strings.Builder, schemaName string, table *storepb.TableMet
}
}
-func writeIndex(out *strings.Builder, schemaName string, tableName string, index *storepb.IndexMetadata) {
+func writeClusteredColumnStoreIndex(out *strings.Builder, schemaName string, tableName string, index *storepb.IndexMetadata) {
+ _, _ = fmt.Fprintf(out, "CREATE CLUSTERED COLUMNSTORE INDEX [%s] ON [%s].[%s];\n\n", index.Name, schemaName, tableName)
+}
+
+func writeNonClusteredColumnStoreIndex(out *strings.Builder, schemaName string, tableName string, index *storepb.IndexMetadata) {
+ _, _ = fmt.Fprintf(out, "CREATE NONCLUSTERED COLUMNSTORE INDEX [%s] ON [%s].[%s] (\n", index.Name, schemaName, tableName)
+ for i, column := range index.Expressions {
+ if i != 0 {
+ _, _ = out.WriteString(",\n")
+ }
+ _, _ = fmt.Fprintf(out, " [%s]", column)
+ }
+ _, _ = out.WriteString("\n);\n\n")
+}
+
+func writeNormalIndex(out *strings.Builder, schemaName string, tableName string, index *storepb.IndexMetadata) {
_, _ = out.WriteString("CREATE")
if index.Type != "" {
_, _ = fmt.Fprintf(out, " %s", index.Type)
@@ -103,6 +118,17 @@ func writeIndex(out *strings.Builder, schemaName string, tableName string, index
_, _ = out.WriteString("\n);\n\n")
}
+func writeIndex(out *strings.Builder, schemaName string, tableName string, index *storepb.IndexMetadata) {
+ switch strings.ToUpper(index.Type) {
+ case "CLUSTERED COLUMNSTORE":
+ writeClusteredColumnStoreIndex(out, schemaName, tableName, index)
+ case "NONCLUSTERED COLUMNSTORE":
+ writeNonClusteredColumnStoreIndex(out, schemaName, tableName, index)
+ default:
+ writeNormalIndex(out, schemaName, tableName, index)
+ }
+}
+
func writeCheck(out *strings.Builder, check *storepb.CheckConstraintMetadata) {
_, _ = fmt.Fprintf(out, " CONSTRAINT [%s] CHECK %s", check.Name, check.Expression)
}