diff --git a/go/libraries/doltcore/merge/merge_prolly_rows.go b/go/libraries/doltcore/merge/merge_prolly_rows.go index f279b4afa0..46f8655b4b 100644 --- a/go/libraries/doltcore/merge/merge_prolly_rows.go +++ b/go/libraries/doltcore/merge/merge_prolly_rows.go @@ -749,8 +749,7 @@ func (idx uniqIndex) insertRow(ctx context.Context, key, value val.Tuple) error return err } - newValue := val.NewTuple(idx.secondary.NodeStore().Pool(), nil) - return idx.secondary.Put(ctx, secondaryIndexKey, newValue) + return idx.secondary.Put(ctx, secondaryIndexKey, val.EmptyTuple) } func (idx uniqIndex) removeRow(ctx context.Context, key, value val.Tuple) error { diff --git a/go/libraries/doltcore/merge/mutable_secondary_index.go b/go/libraries/doltcore/merge/mutable_secondary_index.go index 062402edd5..6c99f52d59 100644 --- a/go/libraries/doltcore/merge/mutable_secondary_index.go +++ b/go/libraries/doltcore/merge/mutable_secondary_index.go @@ -125,14 +125,9 @@ func (m MutableSecondaryIdx) UpdateEntry(ctx context.Context, key, currValue, ne err = m.mut.Delete(ctx, currKey) if err != nil { - return nil + return err } - err = m.mut.Put(ctx, newKey, val.EmptyTuple) - if err != nil { - return nil - } - - return nil + return m.mut.Put(ctx, newKey, val.EmptyTuple) } // DeleteEntry deletes a secondary index entry given they key and value of the primary row. @@ -142,11 +137,7 @@ func (m MutableSecondaryIdx) DeleteEntry(ctx context.Context, key val.Tuple, val return err } - err = m.mut.Delete(ctx, currKey) - if err != nil { - return nil - } - return nil + return m.mut.Delete(ctx, currKey) } // Map returns the finalized prolly.Map of the underlying prolly.MutableMap. diff --git a/go/libraries/doltcore/sqle/index/key_builder.go b/go/libraries/doltcore/sqle/index/key_builder.go index 69e9d8d35f..824221977c 100644 --- a/go/libraries/doltcore/sqle/index/key_builder.go +++ b/go/libraries/doltcore/sqle/index/key_builder.go @@ -79,10 +79,16 @@ func (b SecondaryKeyBuilder) SecondaryKeyFromRow(ctx context.Context, k, v val.T for to := range b.mapping { from := b.mapping.MapOrdinal(to) if from < b.split { - // the from field comes from the key tuple fields + // the "from" field comes from the key tuple fields + // NOTE: Because we are using Tuple.GetField and TupleBuilder.PutRaw, we are not + // interpreting the tuple data at all and just copying the bytes. This should work + // for primary keys since they are always represented in the secondary index exactly + // as they are in the primary index, but for the value tuple, we need to interpret the + // data so that we can transform StringAddrEnc fields from pointers to strings (i.e. for + // prefix indexes) as well as custom handling for ZCell geometry fields. b.builder.PutRaw(to, k.GetField(from)) } else { - // the from field comes from the value tuple fields + // the "from" field comes from the value tuple fields from -= b.split value, err := GetField(ctx, b.sch.GetValueDescriptor(), from, v, b.nodeStore) diff --git a/go/libraries/doltcore/table/editor/creation/index.go b/go/libraries/doltcore/table/editor/creation/index.go index 516c82f995..a80db936dd 100644 --- a/go/libraries/doltcore/table/editor/creation/index.go +++ b/go/libraries/doltcore/table/editor/creation/index.go @@ -202,8 +202,7 @@ func BuildSecondaryProllyIndex(ctx context.Context, vrw types.ValueReadWriter, n if err != nil { return nil, err } - idxVal := val.EmptyTuple - if err = mut.Put(ctx, idxKey, idxVal); err != nil { + if err = mut.Put(ctx, idxKey, val.EmptyTuple); err != nil { return nil, err } } @@ -272,7 +271,6 @@ func BuildUniqueProllyIndex(ctx context.Context, vrw types.ValueReadWriter, ns t if err != nil { return nil, err } - idxVal := val.EmptyTuple if prefixDesc.HasNulls(idxKey) { continue @@ -289,7 +287,7 @@ func BuildUniqueProllyIndex(ctx context.Context, vrw types.ValueReadWriter, ns t return nil, err } - if err = mut.Put(ctx, idxKey, idxVal); err != nil { + if err = mut.Put(ctx, idxKey, val.EmptyTuple); err != nil { return nil, err } } diff --git a/go/store/prolly/mutable_map_write_test.go b/go/store/prolly/mutable_map_write_test.go index 9830580954..a4b4b1c5bf 100644 --- a/go/store/prolly/mutable_map_write_test.go +++ b/go/store/prolly/mutable_map_write_test.go @@ -489,8 +489,7 @@ func testInternalNodeSplits(t *testing.T) { bld.PutInt32(0, int32(j)) bld.PutInt32(1, int32(j)) key := bld.Build(sharedPool) - value := val.EmptyTuple - err = mut.Put(ctx, key, value) + err = mut.Put(ctx, key, val.EmptyTuple) require.NoError(t, err) } pm, err = mut.Map(ctx)