diff --git a/br/tests/lightning_foreign_key/data/fk.child-schema.sql b/br/tests/lightning_foreign_key/data/fk.child-schema.sql new file mode 100644 index 0000000000000..18c361bf4c2e0 --- /dev/null +++ b/br/tests/lightning_foreign_key/data/fk.child-schema.sql @@ -0,0 +1 @@ +create table child (id int key, pid int, constraint fk_1 foreign key (pid) references parent(id)); diff --git a/br/tests/lightning_foreign_key/data/fk.child.sql b/br/tests/lightning_foreign_key/data/fk.child.sql new file mode 100644 index 0000000000000..12e531eb96a34 --- /dev/null +++ b/br/tests/lightning_foreign_key/data/fk.child.sql @@ -0,0 +1 @@ +insert into child values (1,1),(2,2),(3,3),(4,4); diff --git a/br/tests/lightning_foreign_key/data/fk.parent-schema.sql b/br/tests/lightning_foreign_key/data/fk.parent-schema.sql new file mode 100644 index 0000000000000..8ae8af2de6a2e --- /dev/null +++ b/br/tests/lightning_foreign_key/data/fk.parent-schema.sql @@ -0,0 +1 @@ +create table parent(id int key, a int); diff --git a/br/tests/lightning_foreign_key/data/fk.parent.sql b/br/tests/lightning_foreign_key/data/fk.parent.sql new file mode 100644 index 0000000000000..7a31a9f18db0f --- /dev/null +++ b/br/tests/lightning_foreign_key/data/fk.parent.sql @@ -0,0 +1 @@ +insert into parent values (1,1),(2,2),(3,3),(4,4); diff --git a/br/tests/lightning_foreign_key/run.sh b/br/tests/lightning_foreign_key/run.sh old mode 100644 new mode 100755 index 631b55d907102..1c045b61f43be --- a/br/tests/lightning_foreign_key/run.sh +++ b/br/tests/lightning_foreign_key/run.sh @@ -16,13 +16,23 @@ set -eu -# Create existing tables that import data will reference. +run_sql 'DROP DATABASE IF EXISTS fk;' run_sql 'CREATE DATABASE IF NOT EXISTS fk;' +# Create existing tables that import data will reference. run_sql 'CREATE TABLE fk.t2 (a BIGINT PRIMARY KEY);' for BACKEND in tidb local; do - run_sql 'DROP TABLE IF EXISTS fk.t;' + run_sql 'DROP TABLE IF EXISTS fk.t, fk.parent, fk.child;' + run_lightning --backend $BACKEND run_sql 'SELECT GROUP_CONCAT(a) FROM fk.t ORDER BY a;' check_contains '1,2,3,4,5' + + run_sql 'SELECT count(1), sum(a) FROM fk.parent;' + check_contains 'count(1): 4' + check_contains 'sum(a): 10' + + run_sql 'SELECT count(1), sum(pid) FROM fk.child;' + check_contains 'count(1): 4' + check_contains 'sum(pid): 10' done