dolt icon indicating copy to clipboard operation
dolt copied to clipboard

`dolt merge` silently violates check constraints

Open druvv opened this issue 2 years ago • 2 comments

Repro:

dolt init
dolt sql <<SQL
CREATE TABLE t (
    pk int PRIMARY KEY, 
    col1 int, col2 int, 
    CHECK (col1 != col2)
);
INSERT INTO t VALUES (1, 2, 3);
CALL DOLT_COMMIT('-am', 'insert test row');

CALL DOLT_CHECKOUT('-b', 'right');
UPDATE t SET col1 = 4 where pk = 1;
CALL DOLT_COMMIT('-am', 'update col1 to 4');

CALL DOLT_CHECKOUT('main');
UPDATE t set col2 = 4 where pk = 1;
CALL DOLT_COMMIT('-am', 'update col2 to 4');

CALL DOLT_MERGE('right');
SQL

Merge Output:

+--------------+
| no_conflicts |
+--------------+
| 1            |
+--------------+

Our constraint is violated and no errors are produced:

> SELECT * from t;
+----+------+------+
| pk | col1 | col2 |
+----+------+------+
| 1  | 4    | 4    |
+----+------+------+

druvv avatar May 20 '22 17:05 druvv

Slight mod to the repro:

dolt sql <<SQL
CREATE TABLE t (
    pk int PRIMARY KEY, 
    col1 int, col2 int, 
    CHECK (col1 != col2)
);
INSERT INTO t VALUES (1, 2, 3);
CALL DOLT_ADD('t');
CALL DOLT_COMMIT('-am', 'insert test row');

CALL DOLT_CHECKOUT('-b', 'right');
UPDATE t SET col1 = 4 where pk = 1;
CALL DOLT_COMMIT('-am', 'update col1 to 4');

CALL DOLT_CHECKOUT('main');
UPDATE t set col2 = 4 where pk = 1;
CALL DOLT_COMMIT('-am', 'update col2 to 4');

CALL DOLT_MERGE('right');
SQL

timsehn avatar Aug 31 '22 00:08 timsehn

We do check foreign key and unique key constraints on merge.

timsehn avatar Aug 31 '22 00:08 timsehn