Skip to content

Commit

Permalink
dumpling, lightning: add partition table test cases (#57619)
Browse files Browse the repository at this point in the history
close #57623
  • Loading branch information
Defined2014 authored Nov 22, 2024
1 parent bc03ed8 commit 6e22b8c
Show file tree
Hide file tree
Showing 19 changed files with 196 additions and 37 deletions.
13 changes: 13 additions & 0 deletions dumpling/tests/partition_table/data/pt_case_0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
create table `pt_case_0` (a int, b int, unique index idx(a) global) partition by hash(b) partitions 5;
insert into `pt_case_0` values
(0, 10),
(1, 9),
(2, 8),
(3, 7),
(4, 6),
(5, 5),
(6, 4),
(7, 3),
(8, 2),
(9, 1),
(10, 0);
16 changes: 16 additions & 0 deletions dumpling/tests/partition_table/data/pt_case_1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
create table `pt_case_1` (a int, b int, unique index idx(a) global) partition by list(b)
(partition p0 values in (0, 1, 2, 3),
partition p1 values in (4, 5, 6),
partition p2 values in (7, 8, 9, 10));
insert into `pt_case_1` values
(0, 10),
(1, 9),
(2, 8),
(3, 7),
(4, 6),
(5, 5),
(6, 4),
(7, 3),
(8, 2),
(9, 1),
(10, 0);
16 changes: 16 additions & 0 deletions dumpling/tests/partition_table/data/pt_case_2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
create table `pt_case_2` (a int, b int, unique index idx(a) global) partition by range(b)
(partition p0 values less than (4),
partition p1 values less than (7),
partition p2 values less than (11));
insert into `pt_case_2` values
(0, 10),
(1, 9),
(2, 8),
(3, 7),
(4, 6),
(5, 5),
(6, 4),
(7, 3),
(8, 2),
(9, 1),
(10, 0);
8 changes: 8 additions & 0 deletions dumpling/tests/partition_table/result/pt_case_0-schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*!40014 SET FOREIGN_KEY_CHECKS=0*/;
/*!40101 SET NAMES binary*/;
CREATE TABLE `pt_case_0` (
`a` int DEFAULT NULL,
`b` int DEFAULT NULL,
UNIQUE KEY `idx` (`a`) /*T![global_index] GLOBAL */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY HASH (`b`) PARTITIONS 5;
14 changes: 14 additions & 0 deletions dumpling/tests/partition_table/result/pt_case_0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*!40014 SET FOREIGN_KEY_CHECKS=0*/;
/*!40101 SET NAMES binary*/;
INSERT INTO `pt_case_0` VALUES
(0,10),
(1,9),
(2,8),
(3,7),
(4,6),
(5,5),
(6,4),
(7,3),
(8,2),
(9,1),
(10,0);
11 changes: 11 additions & 0 deletions dumpling/tests/partition_table/result/pt_case_1-schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*!40014 SET FOREIGN_KEY_CHECKS=0*/;
/*!40101 SET NAMES binary*/;
CREATE TABLE `pt_case_1` (
`a` int DEFAULT NULL,
`b` int DEFAULT NULL,
UNIQUE KEY `idx` (`a`) /*T![global_index] GLOBAL */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY LIST (`b`)
(PARTITION `p0` VALUES IN (0,1,2,3),
PARTITION `p1` VALUES IN (4,5,6),
PARTITION `p2` VALUES IN (7,8,9,10));
14 changes: 14 additions & 0 deletions dumpling/tests/partition_table/result/pt_case_1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*!40014 SET FOREIGN_KEY_CHECKS=0*/;
/*!40101 SET NAMES binary*/;
INSERT INTO `pt_case_1` VALUES
(0,10),
(1,9),
(2,8),
(3,7),
(4,6),
(5,5),
(6,4),
(7,3),
(8,2),
(9,1),
(10,0);
11 changes: 11 additions & 0 deletions dumpling/tests/partition_table/result/pt_case_2-schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*!40014 SET FOREIGN_KEY_CHECKS=0*/;
/*!40101 SET NAMES binary*/;
CREATE TABLE `pt_case_2` (
`a` int DEFAULT NULL,
`b` int DEFAULT NULL,
UNIQUE KEY `idx` (`a`) /*T![global_index] GLOBAL */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY RANGE (`b`)
(PARTITION `p0` VALUES LESS THAN (4),
PARTITION `p1` VALUES LESS THAN (7),
PARTITION `p2` VALUES LESS THAN (11));
14 changes: 14 additions & 0 deletions dumpling/tests/partition_table/result/pt_case_2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*!40014 SET FOREIGN_KEY_CHECKS=0*/;
/*!40101 SET NAMES binary*/;
INSERT INTO `pt_case_2` VALUES
(0,10),
(1,9),
(2,8),
(3,7),
(4,6),
(5,5),
(6,4),
(7,3),
(8,2),
(9,1),
(10,0);
27 changes: 27 additions & 0 deletions dumpling/tests/partition_table/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh
#
# Copyright 2024 PingCAP, Inc. Licensed under Apache-2.0.

set -eu

export DUMPLING_TEST_PORT=4000

run_sql "drop database if exists partition_table"
run_sql "create database partition_table DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"
export DUMPLING_TEST_DATABASE=partition_table

for data in "$DUMPLING_BASE_NAME"/data/*; do
run_sql_file "$data"
done

run_dumpling

for file_path in "$DUMPLING_BASE_NAME"/data/*; do
base_name=$(basename "$file_path")
table_name="${base_name%.sql}"
file_should_exist "$DUMPLING_BASE_NAME/result/$table_name.sql"
file_should_exist "$DUMPLING_OUTPUT_DIR/partition_table.$table_name.000000000.sql"
file_should_exist "$DUMPLING_OUTPUT_DIR/partition_table.$table_name-schema.sql"
diff "$DUMPLING_BASE_NAME/result/$table_name.sql" "$DUMPLING_OUTPUT_DIR/partition_table.$table_name.000000000.sql"
diff "$DUMPLING_BASE_NAME/result/$table_name-schema.sql" "$DUMPLING_OUTPUT_DIR/partition_table.$table_name-schema.sql"
done
Original file line number Diff line number Diff line change
@@ -1 +1 @@
create table a (a int, b varchar(16), KEY key_b (`b`)) partition by hash(a) partitions 5;
create table a (a int, b varchar(16), c int, KEY key_b (`b`), unique index key_c(c) global) partition by hash(a) partitions 5;
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
insert into a values
(268435456, '268435456'),
(1, 'adgagdadgagag'),
(262144, 'gadgagaha'),
(32, '32'),
(4, 'hahaha'),
(65536, 'luck dog'),
(8388608, 'heyhey'),
(0, '999');
(268435456, '268435456', 268435456),
(1, 'adgagdadgagag', 1),
(262144, 'gadgagaha', 262144),
(32, '32', 32),
(4, 'hahaha', 4),
(65536, 'luck dog', 65536),
(8388608, 'heyhey', 8388608),
(0, '999', 0);

Original file line number Diff line number Diff line change
@@ -1 +1 @@
create table `defaultlist` (a int, b varchar(16), KEY key_b (`b`)) partition by list(a) (partition p1 values in (1,4,8),partition p2 values in (32,default), partition p3 values in (262144,65536));
create table `defaultlist` (a int, b varchar(16), c int, KEY key_b (`b`), unique index key_c(`c`) global) partition by list(a) (partition p1 values in (1,4,8),partition p2 values in (32,default), partition p3 values in (262144,65536));
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
insert into defaultlist values
(268435456, '268435456'),
(1, 'adgagdadgagag'),
(262144, 'gadgagaha'),
(32, '32'),
(4, 'hahaha'),
(65536, 'luck dog'),
(8388608, 'heyhey'),
(0, '999');

(268435456, '268435456', 268435456),
(1, 'adgagdadgagag', 1),
(262144, 'gadgagaha', 262144),
(32, '32', 32),
(4, 'hahaha', 4),
(65536, 'luck dog', 65536),
(8388608, 'heyhey', 8388608),
(0, '999', 0);
Original file line number Diff line number Diff line change
@@ -1 +1 @@
create table `list` (a int, b varchar(16), KEY key_b (`b`)) partition by list(a) (partition p1 values in (1,4,8),partition p2 values in (32,8388608,268435456), partition p3 values in (262144,0,65536));
create table `list` (a int, b varchar(16), c int, KEY key_b (`b`), unique index key_c(`c`) global) partition by list(a) (partition p1 values in (1,4,8),partition p2 values in (32,8388608,268435456), partition p3 values in (262144,0,65536));
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
insert into list values
(268435456, '268435456'),
(1, 'adgagdadgagag'),
(262144, 'gadgagaha'),
(32, '32'),
(4, 'hahaha'),
(65536, 'luck dog'),
(8388608, 'heyhey'),
(0, '999');
(268435456, '268435456', 268435456),
(1, 'adgagdadgagag', 1),
(262144, 'gadgagaha', 262144),
(32, '32', 32),
(4, 'hahaha', 4),
(65536, 'luck dog', 65536),
(8388608, 'heyhey', 8388608),
(0, '999', 0);

Original file line number Diff line number Diff line change
@@ -1 +1 @@
create table `range` (a int, b varchar(16), KEY key_b (`b`)) partition by range(a) (partition pNeg values less than (0), partition pMax values less than (maxvalue));
create table `range` (a int, b varchar(16), c int, KEY key_b (`b`), unique index key_c(`c`) global) partition by range(a) (partition pNeg values less than (0), partition pMax values less than (maxvalue));
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
insert into range values
(268435456, '268435456'),
(1, 'adgagdadgagag'),
(262144, 'gadgagaha'),
(32, '32'),
(4, 'hahaha'),
(65536, 'luck dog'),
(8388608, 'heyhey'),
(0, '999');
(268435456, '268435456', 268435456),
(1, 'adgagdadgagag', 1),
(262144, 'gadgagaha', 262144),
(32, '32', 32),
(4, 'hahaha', 4),
(65536, 'luck dog', 65536),
(8388608, 'heyhey', 8388608),
(0, '999', 0);

16 changes: 16 additions & 0 deletions lightning/tests/lightning_partitioned-table/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,43 @@ for BACKEND in tidb local; do
check_contains 'count(1): 8'
check_contains 'sum(a): 277151781'

run_sql 'SELECT count(1), sum(c) FROM partitioned.a use index (key_c);'
check_contains 'count(1): 8'
check_contains 'sum(c): 277151781'

run_sql "SHOW TABLE STATUS FROM partitioned WHERE name = 'a';"
check_contains 'Create_options: partitioned'

run_sql 'SELECT count(1), sum(a) FROM partitioned.range;'
check_contains 'count(1): 8'
check_contains 'sum(a): 277151781'

run_sql 'SELECT count(1), sum(c) FROM partitioned.range use index (key_c);'
check_contains 'count(1): 8'
check_contains 'sum(c): 277151781'

run_sql "SHOW TABLE STATUS FROM partitioned WHERE name = 'range';"
check_contains 'Create_options: partitioned'

run_sql 'SELECT count(1), sum(a) FROM partitioned.list;'
check_contains 'count(1): 8'
check_contains 'sum(a): 277151781'

run_sql 'SELECT count(1), sum(c) FROM partitioned.list use index (key_c);'
check_contains 'count(1): 8'
check_contains 'sum(c): 277151781'

run_sql "SHOW TABLE STATUS FROM partitioned WHERE name = 'list';"
check_contains 'Create_options: partitioned'

run_sql 'SELECT count(1), sum(a) FROM partitioned.defaultlist;'
check_contains 'count(1): 8'
check_contains 'sum(a): 277151781'

run_sql 'SELECT count(1), sum(c) FROM partitioned.defaultlist use index (key_c);'
check_contains 'count(1): 8'
check_contains 'sum(c): 277151781'

run_sql "SHOW TABLE STATUS FROM partitioned WHERE name = 'defaultlist';"
check_contains 'Create_options: partitioned'
done

0 comments on commit 6e22b8c

Please sign in to comment.