Skip to content

Commit

Permalink
lightning: add foreign key test (#40103)
Browse files Browse the repository at this point in the history
close #40226
  • Loading branch information
crazycs520 authored Dec 29, 2022
1 parent 6dff69f commit 875c002
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions br/tests/lightning_foreign_key/data/fk.child-schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create table child (id int key, pid int, constraint fk_1 foreign key (pid) references parent(id));
1 change: 1 addition & 0 deletions br/tests/lightning_foreign_key/data/fk.child.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
insert into child values (1,1),(2,2),(3,3),(4,4);
1 change: 1 addition & 0 deletions br/tests/lightning_foreign_key/data/fk.parent-schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create table parent(id int key, a int);
1 change: 1 addition & 0 deletions br/tests/lightning_foreign_key/data/fk.parent.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
insert into parent values (1,1),(2,2),(3,3),(4,4);
14 changes: 12 additions & 2 deletions br/tests/lightning_foreign_key/run.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 875c002

Please sign in to comment.