Merge pull request #5157 from dolthub/dhruv/fix-fritter-bug

Fix `call DOLT_VERIFY_CONSTRAINTS()` false-positive
This commit is contained in:
Dhruv Sringari
2023-01-18 10:49:36 -08:00
committed by GitHub
3 changed files with 47 additions and 5 deletions

View File

@@ -661,7 +661,7 @@ func newConstraintViolationsLoadedTable(ctx context.Context, tblName, idxName st
IsUserDefined: false,
Comment: "",
}
pkIdx := schema.NewIndex("", pkCols.SortedTags, pkCols.SortedTags, pkIdxColl, pkIdxProps)
pkIdx := schema.NewIndex("", pkCols.Tags, pkCols.Tags, pkIdxColl, pkIdxProps)
return &constraintViolationsLoadedTable{
TableName: trueTblName,
Table: tbl,

View File

@@ -43,7 +43,7 @@ func prollyParentFkConstraintViolations(
postParentRowData := durable.ProllyMapFromIndex(postParent.RowData)
postParentIndexData := durable.ProllyMapFromIndex(postParent.IndexData)
idxDesc := postParent.Index.Schema().GetKeyDescriptor()
idxDesc, _ := postParentIndexData.Descriptors()
partialDesc := idxDesc.PrefixDesc(len(foreignKey.TableColumns))
partialKB := val.NewTupleBuilder(partialDesc)
@@ -103,13 +103,12 @@ func prollyChildFkConstraintViolations(
preChildRowData prolly.Map,
receiver FKViolationReceiver) error {
postChildRowData := durable.ProllyMapFromIndex(postChild.RowData)
parentScndryIdx := durable.ProllyMapFromIndex(postParent.IndexData)
idxDesc := postChild.Index.Schema().GetKeyDescriptor()
idxDesc, _ := parentScndryIdx.Descriptors()
partialDesc := idxDesc.PrefixDesc(len(foreignKey.TableColumns))
partialKB := val.NewTupleBuilder(partialDesc)
parentScndryIdx := durable.ProllyMapFromIndex(postParent.IndexData)
err := prolly.DiffMaps(ctx, preChildRowData, postChildRowData, func(ctx context.Context, diff tree.Diff) error {
switch diff.Type {
case tree.AddedDiff, tree.ModifiedDiff:

View File

@@ -3050,6 +3050,49 @@ var DoltVerifyConstraintsTestScripts = []queries.ScriptTest{
},
},
},
{
Name: "verify-constraints: Regression test for bad compound primary key reuse as foreign key index - no error",
SetUpScript: []string{
"create table parent (col1 int not null, col2 float not null, primary key (col1, col2));",
"create table child (col1 int not null, col2 float not null, col3 int not null, col4 float not null, col5 int not null, col6 float not null, primary key (col1, col2, col3, col4, col5, col6), foreign key (col1, col2) references parent (col1, col2));",
"set foreign_key_checks = 0;",
"insert into parent values (1, 2.5), (7, 8.5);",
"insert into child values (1, 2.5, 3, 4.5, 5, 6.5), (7, 8.5, 9, 10.5, 11, 12.5);",
"set foreign_key_checks = 1;",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "call DOLT_VERIFY_CONSTRAINTS('--all');",
Expected: []sql.Row{{0}},
},
{
Query: "select * from dolt_constraint_violations;",
Expected: []sql.Row{},
},
},
},
{
Name: "verify-constraints: Regression test for bad compound primary key reuse as foreign key index - error",
SetUpScript: []string{
"create table parent (col1 int not null, col2 float not null, primary key (col1, col2));",
"create table child (col1 int not null, col2 float not null, col3 int not null, col4 float not null, col5 int not null, col6 float not null, primary key (col1, col2, col3, col4, col5, col6), foreign key (col1, col2) references parent (col1, col2));",
"set foreign_key_checks = 0;",
"insert into parent values (1, 2.5);",
"insert into child values (1, 2.5, 3, 4.5, 5, 6.5), (7, 8.5, 9, 10.5, 11, 12.5);",
"set foreign_key_checks = 1;",
"set dolt_force_transaction_commit = 1;",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "call DOLT_VERIFY_CONSTRAINTS('--all');",
Expected: []sql.Row{{1}},
},
{
Query: "select * from dolt_constraint_violations;",
Expected: []sql.Row{{"child", uint64(1)}},
},
},
},
}
var errTmplNoAutomaticMerge = "table %s can't be automatically merged.\nTo merge this table, make the schema on the source and target branch equal."