diff --git a/go/cmd/dolt/commands/schcmds/import.go b/go/cmd/dolt/commands/schcmds/import.go index c4cb9da28f7..56c86d5fdfa 100644 --- a/go/cmd/dolt/commands/schcmds/import.go +++ b/go/cmd/dolt/commands/schcmds/import.go @@ -330,7 +330,7 @@ func putEmptyTableWithSchema(ctx context.Context, tblName string, root doltdb.Ro return nil, errhand.BuildDError("error: failed to get table.").AddCause(err).Build() } - empty, err := durable.NewEmptyIndex(ctx, root.VRW(), root.NodeStore(), sch, false) + empty, err := durable.NewEmptyPrimaryIndex(ctx, root.VRW(), root.NodeStore(), sch) if err != nil { return nil, errhand.BuildDError("error: failed to get table.").AddCause(err).Build() } diff --git a/go/libraries/doltcore/doltdb/commit_hooks_test.go b/go/libraries/doltcore/doltdb/commit_hooks_test.go index e94894acd3c..fa20ac9c52e 100644 --- a/go/libraries/doltcore/doltdb/commit_hooks_test.go +++ b/go/libraries/doltcore/doltdb/commit_hooks_test.go @@ -251,7 +251,7 @@ func TestAsyncPushOnWrite(t *testing.T) { assert.NoError(t, err) tSchema := createTestSchema(t) - rowData, err := durable.NewEmptyIndex(ctx, ddb.vrw, ddb.ns, tSchema, false) + rowData, err := durable.NewEmptyPrimaryIndex(ctx, ddb.vrw, ddb.ns, tSchema) require.NoError(t, err) tbl, err := CreateTestTable(ddb.vrw, ddb.ns, tSchema, rowData) require.NoError(t, err) diff --git a/go/libraries/doltcore/doltdb/doltdb_test.go b/go/libraries/doltcore/doltdb/doltdb_test.go index 5332ac8f987..ef1f09de50e 100644 --- a/go/libraries/doltcore/doltdb/doltdb_test.go +++ b/go/libraries/doltcore/doltdb/doltdb_test.go @@ -83,7 +83,7 @@ func CreateTestTable(vrw types.ValueReadWriter, ns tree.NodeStore, tSchema schem func createTestRowData(t *testing.T, vrw types.ValueReadWriter, ns tree.NodeStore, sch schema.Schema) durable.Index { if types.Format_Default == types.Format_DOLT { - idx, err := durable.NewEmptyIndex(context.Background(), vrw, ns, sch, false) + idx, err := durable.NewEmptyPrimaryIndex(context.Background(), vrw, ns, sch) require.NoError(t, err) return idx } @@ -303,7 +303,7 @@ func TestLDNoms(t *testing.T) { ctx := context.Background() tSchema := createTestSchema(t) - rowData, err := durable.NewEmptyIndex(ctx, ddb.vrw, ddb.ns, tSchema, false) + rowData, err := durable.NewEmptyPrimaryIndex(ctx, ddb.vrw, ddb.ns, tSchema) if err != nil { t.Fatal("Failed to create new empty index") } diff --git a/go/libraries/doltcore/doltdb/durable/index.go b/go/libraries/doltcore/doltdb/durable/index.go index aa765fd8be8..29a3e136e44 100644 --- a/go/libraries/doltcore/doltdb/durable/index.go +++ b/go/libraries/doltcore/doltdb/durable/index.go @@ -18,6 +18,7 @@ import ( "bytes" "context" "fmt" + "github.com/dolthub/go-mysql-server/sql/expression/function/vector" "io" "strings" @@ -123,8 +124,17 @@ func indexFromAddr(ctx context.Context, vrw types.ValueReadWriter, ns tree.NodeS } } -// NewEmptyIndex returns an index with no rows. -func NewEmptyIndex(ctx context.Context, vrw types.ValueReadWriter, ns tree.NodeStore, sch schema.Schema, isKeylessSecondary bool) (Index, error) { +func NewEmptyPrimaryIndex(ctx context.Context, vrw types.ValueReadWriter, ns tree.NodeStore, sch schema.Schema) (Index, error) { + return newEmptyIndex(ctx, vrw, ns, sch, false, false) +} + +func NewEmptyIndexFromSchemaIndex(ctx context.Context, vrw types.ValueReadWriter, ns tree.NodeStore, idx schema.Index) (Index, error) { + sch := idx.Schema() + return newEmptyIndex(ctx, vrw, ns, sch, idx.IsVector(), schema.IsKeyless(sch)) +} + +// newEmptyIndex returns an index with no rows. +func newEmptyIndex(ctx context.Context, vrw types.ValueReadWriter, ns tree.NodeStore, sch schema.Schema, isVector bool, isKeylessSecondary bool) (Index, error) { switch vrw.Format() { case types.Format_LD_1: m, err := types.NewMap(ctx, vrw) @@ -138,17 +148,21 @@ func NewEmptyIndex(ctx context.Context, vrw types.ValueReadWriter, ns tree.NodeS if isKeylessSecondary { kd = prolly.AddHashToSchema(kd) } - m, err := prolly.NewMapFromTuples(ctx, ns, kd, vd) - if err != nil { - return nil, err - } - return IndexFromProllyMap(m), nil + return NewEmptyProllyIndex(ctx, ns, kd, vd) default: return nil, errNbfUnknown } } +func NewEmptyProllyIndex(ctx context.Context, ns tree.NodeStore, kd, vd val.TupleDesc) (Index, error) { + m, err := prolly.NewMapFromTuples(ctx, ns, kd, vd) + if err != nil { + return nil, err + } + return IndexFromProllyMap(m), nil +} + type nomsIndex struct { index types.Map vrw types.ValueReadWriter @@ -393,7 +407,7 @@ func NewIndexSetWithEmptyIndexes(ctx context.Context, vrw types.ValueReadWriter, return nil, err } for _, index := range sch.Indexes().AllIndexes() { - empty, err := NewEmptyIndex(ctx, vrw, ns, index.Schema(), false) + empty, err := NewEmptyIndexFromSchemaIndex(ctx, vrw, ns, index) if err != nil { return nil, err } diff --git a/go/libraries/doltcore/doltdb/root_val.go b/go/libraries/doltcore/doltdb/root_val.go index d079e7651f8..2f4ff1c3510 100644 --- a/go/libraries/doltcore/doltdb/root_val.go +++ b/go/libraries/doltcore/doltdb/root_val.go @@ -924,7 +924,7 @@ func (root *rootValue) putTable(ctx context.Context, tName TableName, ref types. func CreateEmptyTable(ctx context.Context, root RootValue, tName TableName, sch schema.Schema) (RootValue, error) { ns := root.NodeStore() vrw := root.VRW() - empty, err := durable.NewEmptyIndex(ctx, vrw, ns, sch, false) + empty, err := durable.NewEmptyPrimaryIndex(ctx, vrw, ns, sch) if err != nil { return nil, err } diff --git a/go/libraries/doltcore/doltdb/table.go b/go/libraries/doltcore/doltdb/table.go index bafce8b00f3..45154941e05 100644 --- a/go/libraries/doltcore/doltdb/table.go +++ b/go/libraries/doltcore/doltdb/table.go @@ -92,7 +92,7 @@ func NewTableFromDurable(table durable.Table) *Table { } func NewEmptyTable(ctx context.Context, vrw types.ValueReadWriter, ns tree.NodeStore, sch schema.Schema) (*Table, error) { - rows, err := durable.NewEmptyIndex(ctx, vrw, ns, sch, false) + rows, err := durable.NewEmptyPrimaryIndex(ctx, vrw, ns, sch) if err != nil { return nil, err } diff --git a/go/libraries/doltcore/dtestutils/testcommands/multienv.go b/go/libraries/doltcore/dtestutils/testcommands/multienv.go index 93fef0de294..c79c45926dd 100644 --- a/go/libraries/doltcore/dtestutils/testcommands/multienv.go +++ b/go/libraries/doltcore/dtestutils/testcommands/multienv.go @@ -390,7 +390,7 @@ func createTestTable(dEnv *env.DoltEnv, tableName string, sch schema.Schema) err vrw := dEnv.DoltDB.ValueReadWriter() ns := dEnv.DoltDB.NodeStore() - idx, err := durable.NewEmptyIndex(ctx, vrw, ns, sch, false) + idx, err := durable.NewEmptyPrimaryIndex(ctx, vrw, ns, sch) if err != nil { return err } diff --git a/go/libraries/doltcore/merge/fulltext_rebuild.go b/go/libraries/doltcore/merge/fulltext_rebuild.go index e439e663f1e..e1cf674a19a 100644 --- a/go/libraries/doltcore/merge/fulltext_rebuild.go +++ b/go/libraries/doltcore/merge/fulltext_rebuild.go @@ -330,7 +330,7 @@ func purgeFulltextTableData(ctx *sql.Context, root doltdb.RootValue, tableNames if err != nil { return nil, err } - rows, err := durable.NewEmptyIndex(ctx, tbl.ValueReadWriter(), tbl.NodeStore(), sch, false) + rows, err := durable.NewEmptyPrimaryIndex(ctx, tbl.ValueReadWriter(), tbl.NodeStore(), sch) if err != nil { return nil, err } diff --git a/go/libraries/doltcore/merge/violations_fk.go b/go/libraries/doltcore/merge/violations_fk.go index a2f3233329b..e0832655ea2 100644 --- a/go/libraries/doltcore/merge/violations_fk.go +++ b/go/libraries/doltcore/merge/violations_fk.go @@ -107,7 +107,7 @@ func GetForeignKeyViolations(ctx context.Context, newRoot, baseRoot doltdb.RootV return err } // Parent does not exist in the ancestor so we use an empty map - emptyIdx, err := durable.NewEmptyIndex(ctx, postParent.Table.ValueReadWriter(), postParent.Table.NodeStore(), postParent.Schema, false) + emptyIdx, err := durable.NewEmptyPrimaryIndex(ctx, postParent.Table.ValueReadWriter(), postParent.Table.NodeStore(), postParent.Schema) if err != nil { return err } @@ -129,7 +129,7 @@ func GetForeignKeyViolations(ctx context.Context, newRoot, baseRoot doltdb.RootV return err } // Child does not exist in the ancestor so we use an empty map - emptyIdx, err := durable.NewEmptyIndex(ctx, postChild.Table.ValueReadWriter(), postChild.Table.NodeStore(), postChild.Schema, false) + emptyIdx, err := durable.NewEmptyPrimaryIndex(ctx, postChild.Table.ValueReadWriter(), postChild.Table.NodeStore(), postChild.Schema) if err != nil { return err } @@ -370,7 +370,7 @@ func parentFkConstraintViolations( } var idx durable.Index if empty { - idx, err = durable.NewEmptyIndex(ctx, postChild.Table.ValueReadWriter(), postParent.Table.NodeStore(), postParent.Schema, false) + idx, err = durable.NewEmptyIndexFromSchemaIndex(ctx, postChild.Table.ValueReadWriter(), postParent.Table.NodeStore(), postParent.Index) if err != nil { return err } @@ -405,7 +405,7 @@ func childFkConstraintViolations( } var idx durable.Index if empty { - idx, err = durable.NewEmptyIndex(ctx, postChild.Table.ValueReadWriter(), postChild.Table.NodeStore(), postChild.Schema, false) + idx, err = durable.NewEmptyIndexFromSchemaIndex(ctx, postChild.Table.ValueReadWriter(), postChild.Table.NodeStore(), postChild.Index) if err != nil { return err } diff --git a/go/libraries/doltcore/sqle/alterschema_test.go b/go/libraries/doltcore/sqle/alterschema_test.go index b8e5ffd121c..512e6e0420b 100644 --- a/go/libraries/doltcore/sqle/alterschema_test.go +++ b/go/libraries/doltcore/sqle/alterschema_test.go @@ -269,7 +269,7 @@ func makePeopleTable(ctx context.Context, dEnv *env.DoltEnv) (*env.DoltEnv, erro if err != nil { return nil, err } - rows, err := durable.NewEmptyIndex(ctx, root.VRW(), root.NodeStore(), sch, false) + rows, err := durable.NewEmptyPrimaryIndex(ctx, root.VRW(), root.NodeStore(), sch) if err != nil { return nil, err } diff --git a/go/libraries/doltcore/sqle/common_test.go b/go/libraries/doltcore/sqle/common_test.go index 1c5e3a45137..3e889ece5fc 100644 --- a/go/libraries/doltcore/sqle/common_test.go +++ b/go/libraries/doltcore/sqle/common_test.go @@ -181,7 +181,7 @@ func CreateTestTable(t *testing.T, dEnv *env.DoltEnv, tableName string, sch sche vrw := dEnv.DoltDB.ValueReadWriter() ns := dEnv.DoltDB.NodeStore() - rows, err := durable.NewEmptyIndex(ctx, vrw, ns, sch, false) + rows, err := durable.NewEmptyPrimaryIndex(ctx, vrw, ns, sch) require.NoError(t, err) tbl, err := doltdb.NewTable(ctx, vrw, ns, sch, rows, nil, nil) require.NoError(t, err) diff --git a/go/libraries/doltcore/sqle/dtables/conflicts_tables_prolly.go b/go/libraries/doltcore/sqle/dtables/conflicts_tables_prolly.go index 3201c0d0bff..a9b323ac747 100644 --- a/go/libraries/doltcore/sqle/dtables/conflicts_tables_prolly.go +++ b/go/libraries/doltcore/sqle/dtables/conflicts_tables_prolly.go @@ -415,7 +415,7 @@ func (itr *prollyConflictRowIter) loadTableMaps(ctx *sql.Context, baseHash, thei var idx durable.Index if !ok { - idx, err = durable.NewEmptyIndex(ctx, itr.vrw, itr.ns, itr.ourSch, false) + idx, err = durable.NewEmptyPrimaryIndex(ctx, itr.vrw, itr.ns, itr.ourSch) } else { idx, err = baseTbl.GetRowData(ctx) } diff --git a/go/libraries/doltcore/sqle/dtables/diff_table.go b/go/libraries/doltcore/sqle/dtables/diff_table.go index c69b8f6cd36..4c8573cb9d0 100644 --- a/go/libraries/doltcore/sqle/dtables/diff_table.go +++ b/go/libraries/doltcore/sqle/dtables/diff_table.go @@ -599,7 +599,7 @@ func tableData(ctx *sql.Context, tbl *doltdb.Table, ddb *doltdb.DoltDB) (durable var err error if tbl == nil { - data, err = durable.NewEmptyIndex(ctx, ddb.ValueReadWriter(), ddb.NodeStore(), schema.EmptySchema, false) + data, err = durable.NewEmptyPrimaryIndex(ctx, ddb.ValueReadWriter(), ddb.NodeStore(), schema.EmptySchema) if err != nil { return nil, nil, err } diff --git a/go/libraries/doltcore/sqle/tables.go b/go/libraries/doltcore/sqle/tables.go index c7bbe80f495..3d3bd83fd06 100644 --- a/go/libraries/doltcore/sqle/tables.go +++ b/go/libraries/doltcore/sqle/tables.go @@ -937,7 +937,7 @@ func emptyFulltextTable( return nil, nil, err } - empty, err := durable.NewEmptyIndex(ctx, dt.ValueReadWriter(), dt.NodeStore(), doltSchema, false) + empty, err := durable.NewEmptyPrimaryIndex(ctx, dt.ValueReadWriter(), dt.NodeStore(), doltSchema) if err != nil { return nil, nil, err } @@ -1041,7 +1041,7 @@ func (t *WritableDoltTable) truncate( } for _, idx := range sch.Indexes().AllIndexes() { - empty, err := durable.NewEmptyIndex(ctx, table.ValueReadWriter(), table.NodeStore(), idx.Schema(), false) + empty, err := durable.NewEmptyIndexFromSchemaIndex(ctx, table.ValueReadWriter(), table.NodeStore(), idx) if err != nil { return nil, err } @@ -1065,7 +1065,7 @@ func (t *WritableDoltTable) truncate( } } - empty, err := durable.NewEmptyIndex(ctx, table.ValueReadWriter(), table.NodeStore(), sch, false) + empty, err := durable.NewEmptyPrimaryIndex(ctx, table.ValueReadWriter(), table.NodeStore(), sch) if err != nil { return nil, err } diff --git a/go/libraries/doltcore/sqle/temp_table.go b/go/libraries/doltcore/sqle/temp_table.go index daabc958452..6a07a804d02 100644 --- a/go/libraries/doltcore/sqle/temp_table.go +++ b/go/libraries/doltcore/sqle/temp_table.go @@ -109,7 +109,7 @@ func NewTempTable( vrw := ddb.ValueReadWriter() ns := ddb.NodeStore() - idx, err := durable.NewEmptyIndex(ctx, vrw, ns, sch, false) + idx, err := durable.NewEmptyPrimaryIndex(ctx, vrw, ns, sch) if err != nil { return nil, err } diff --git a/go/libraries/doltcore/sqle/testutil.go b/go/libraries/doltcore/sqle/testutil.go index aa6276acbf2..9af4a26bcba 100644 --- a/go/libraries/doltcore/sqle/testutil.go +++ b/go/libraries/doltcore/sqle/testutil.go @@ -425,7 +425,7 @@ func CreateEmptyTestTable(dEnv *env.DoltEnv, tableName string, sch schema.Schema vrw := dEnv.DoltDB.ValueReadWriter() ns := dEnv.DoltDB.NodeStore() - rows, err := durable.NewEmptyIndex(ctx, vrw, ns, sch, false) + rows, err := durable.NewEmptyPrimaryIndex(ctx, vrw, ns, sch) if err != nil { return err } diff --git a/go/libraries/doltcore/table/editor/creation/external_build_index.go b/go/libraries/doltcore/table/editor/creation/external_build_index.go index 1b7f2e20846..a898aab35da 100644 --- a/go/libraries/doltcore/table/editor/creation/external_build_index.go +++ b/go/libraries/doltcore/table/editor/creation/external_build_index.go @@ -41,7 +41,7 @@ const ( // single prolly tree materialization by presorting the index keys in an // intermediate file format. func BuildProllyIndexExternal(ctx *sql.Context, vrw types.ValueReadWriter, ns tree.NodeStore, sch schema.Schema, tableName string, idx schema.Index, primary prolly.Map, uniqCb DupEntryCb) (durable.Index, error) { - empty, err := durable.NewEmptyIndex(ctx, vrw, ns, idx.Schema(), schema.IsKeyless(sch)) + empty, err := durable.NewEmptyIndexFromSchemaIndex(ctx, vrw, ns, idx.Schema()) if err != nil { return nil, err } diff --git a/go/libraries/doltcore/table/editor/creation/index.go b/go/libraries/doltcore/table/editor/creation/index.go index 7c9ea3a6dc2..347bd1b7587 100644 --- a/go/libraries/doltcore/table/editor/creation/index.go +++ b/go/libraries/doltcore/table/editor/creation/index.go @@ -214,7 +214,7 @@ func BuildUniqueProllyIndex( primary prolly.Map, cb DupEntryCb, ) (durable.Index, error) { - empty, err := durable.NewEmptyIndex(ctx, vrw, ns, idx.Schema(), schema.IsKeyless(sch)) + empty, err := durable.NewEmptyIndexFromSchemaIndex(ctx, vrw, ns, idx) if err != nil { return nil, err } diff --git a/go/libraries/doltcore/table/untyped/sqlexport/sqlwriter_test.go b/go/libraries/doltcore/table/untyped/sqlexport/sqlwriter_test.go index 0332d7576ef..a1580c15318 100644 --- a/go/libraries/doltcore/table/untyped/sqlexport/sqlwriter_test.go +++ b/go/libraries/doltcore/table/untyped/sqlexport/sqlwriter_test.go @@ -92,7 +92,7 @@ func TestEndToEnd(t *testing.T) { root, err := dEnv.WorkingRoot(ctx) require.NoError(t, err) - empty, err := durable.NewEmptyIndex(ctx, root.VRW(), root.NodeStore(), tt.sch, false) + empty, err := durable.NewEmptyPrimaryIndex(ctx, root.VRW(), root.NodeStore(), tt.sch) require.NoError(t, err) indexes, err := durable.NewIndexSet(ctx, root.VRW(), root.NodeStore())