More tidying up

This commit is contained in:
Jason Fulghum
2023-05-22 13:37:27 -07:00
parent 55eab2d7d4
commit 215e852880
2 changed files with 68 additions and 9 deletions

View File

@@ -422,14 +422,12 @@ func (cv checkValidator) validateDiff(ctx *sql.Context, diff tree.ThreeWayDiff)
valueTuple = diff.Merged
valueDesc = cv.tableMerger.leftSch.GetValueDescriptor()
case tree.DiffOpDivergentDeleteConflict, tree.DiffOpDivergentModifyConflict:
// TODO: Add a test case to trigger this... would this even get this far?
return 0, fmt.Errorf("check constraint validation not supported for divergent conflicts")
// Don't bother validating divergent conflicts, just let them get reported as conflicts
return 0, nil
}
// TODO: Do we need to honor column defaults here? Seems like it?
// TEST: A new column with a column default is added, and the column default value causes a check violation
// (check must be just added on one side of the merge to trigger this)
newTuple := valueTuple
// TODO: Why are our tests working without this?!
if false {
// TODO: If we're using diff.Merged, then that means we don't need to do any remapping, right?
// TODO: This right mapping needs to be different, right? for each diff op type?
@@ -448,9 +446,8 @@ func (cv checkValidator) validateDiff(ctx *sql.Context, diff tree.ThreeWayDiff)
}
if result == nil || result == true {
// If a check constraint returns NULL (aka UNKNOWN) or TRUE, then the check constraint is fulfilled
// If a check constraint returns NULL or TRUE, then the check constraint is fulfilled
// https://dev.mysql.com/doc/refman/8.0/en/create-table-check-constraints.html
// TODO: Add a test case for CHECK(NULL = NULL) something that will always return NULL
continue
} else if result == false {
conflictCount++

View File

@@ -4381,11 +4381,73 @@ var ThreeWayMergeWithSchemaChangeTestScripts = []MergeScriptTest{
},
},
},
{
Name: "check constraint violation - divergent edits",
AncSetUpScript: []string{
"set autocommit = 0;",
"CREATE table t (pk int primary key, col1 varchar(100) default ('hello'));",
"INSERT into t values (1, 'hi');",
"alter table t add index idx1 (col1);",
},
RightSetUpScript: []string{
"alter table t add constraint CHECK (col1 != concat('he', 'llo'))",
"update t set col1 = 'bye' where pk=1;",
},
LeftSetUpScript: []string{
"update t set col1 = 'adios' where pk=1;",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "call dolt_merge('right');",
Expected: []sql.Row{{0, 0x1}},
},
},
},
{
Name: "check constraint violation - check is always NULL",
AncSetUpScript: []string{
"CREATE table t (pk int primary key, col1 varchar(100) default ('hello'));",
"INSERT into t values (1, 'hi');",
"alter table t add index idx1 (col1);",
},
RightSetUpScript: []string{
"alter table t add constraint CHECK (NULL = NULL)",
},
LeftSetUpScript: []string{
"insert into t values (2, DEFAULT);",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "call dolt_merge('right');",
Expected: []sql.Row{{0, 0x0}},
},
},
},
{
Name: "check constraint violation - check is always false",
AncSetUpScript: []string{
"SET @@dolt_force_transaction_commit=1;",
"CREATE table t (pk int primary key, col1 varchar(100) default ('hello'));",
"alter table t add index idx1 (col1);",
},
RightSetUpScript: []string{
"alter table t add constraint CHECK (1 = 2)",
},
LeftSetUpScript: []string{
"insert into t values (1, DEFAULT);",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "call dolt_merge('right');",
Expected: []sql.Row{{0, 0x1}},
},
},
},
{
Name: "check constraint violation - left side violates new check constraint",
AncSetUpScript: []string{
"set autocommit = 0;",
"CREATE table t (pk int primary key, col1 varchar(100));",
"CREATE table t (pk int primary key, col1 varchar(100) default ('hello'));",
"INSERT into t values (1, 'hi');",
"alter table t add index idx1 (col1);",
},
@@ -4393,7 +4455,7 @@ var ThreeWayMergeWithSchemaChangeTestScripts = []MergeScriptTest{
"alter table t add constraint CHECK (col1 != concat('he', 'llo'))",
},
LeftSetUpScript: []string{
"insert into t values (2, 'hello');",
"insert into t values (2, DEFAULT);",
},
Assertions: []queries.ScriptTestAssertion{
{