From e2c8d79ce39bc68a5e82ac949bf5d488667677e9 Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Tue, 3 Feb 2026 17:20:23 -0800 Subject: [PATCH] bug fix: correctly convert secondary to primary key lookups --- .../doltcore/merge/violations_fk_prolly.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/go/libraries/doltcore/merge/violations_fk_prolly.go b/go/libraries/doltcore/merge/violations_fk_prolly.go index 51b3438eb4..edce75afc5 100644 --- a/go/libraries/doltcore/merge/violations_fk_prolly.go +++ b/go/libraries/doltcore/merge/violations_fk_prolly.go @@ -67,10 +67,12 @@ func prollyParentSecDiffFkConstraintViolations( childPrimary := &indexAndKeyDescriptor{ index: childPriIdx, keyDesc: childPriIdxDesc, + schema: postChild.Schema, } childSecondary := &indexAndKeyDescriptor{ index: childSecIdx, keyDesc: childSecIdxDesc, + schema: postChild.IndexSchema, } // We allow foreign keys between types that don't have the same serialization bytes for the same logical values @@ -173,10 +175,12 @@ func prollyParentPriDiffFkConstraintViolations( childPrimary := &indexAndKeyDescriptor{ index: childPriIdx, keyDesc: childPriIdxDesc, + schema: postChild.Schema, } childSecondary := &indexAndKeyDescriptor{ index: childScndryIdx, keyDesc: childSecIdxDesc, + schema: postChild.IndexSchema, } // We allow foreign keys between types that don't have the same serialization bytes for the same logical values @@ -548,6 +552,7 @@ func makeOrdinalMappingForSchemas(from, to *schema.ColCollection) (m val.Ordinal type indexAndKeyDescriptor struct { index prolly.Map keyDesc *val.TupleDesc + schema schema.Schema } // createCVsForDanglingChildRows finds all rows in the childIdx that match the given parent key and creates constraint @@ -611,21 +616,13 @@ func createCVsForDanglingChildRows( return err } - kb := val.NewTupleBuilder(childPrimaryIdx.keyDesc, childPrimaryIdx.index.NodeStore()) - for k, _, err := itr.Next(ctx); err != io.EOF; k, _, err = itr.Next(ctx) { if err != nil { return err } // convert secondary idx entry to primary row key - // the pks of the table are the last keys of the index - o := k.Count() - childPrimaryIdx.keyDesc.Count() - for i := 0; i < childPrimaryIdx.keyDesc.Count(); i++ { - j := o + i - kb.PutRaw(i, k.GetField(j)) - } - primaryIdxKey, err := kb.Build(childPrimaryIdx.index.Pool()) + primaryIdxKey, err := primaryKeyFromSecondaryIndexRow(k, childPrimaryIdx.keyDesc, childPrimaryIdx.index, childPrimaryIdx.schema, childSecIdx.schema) if err != nil { return err }