Skip to content

Commit

Permalink
*: add test cases for non-unique global index (#59012)
Browse files Browse the repository at this point in the history
ref #58650
  • Loading branch information
Defined2014 authored Jan 17, 2025
1 parent db7843a commit 2fafd20
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 16 deletions.
3 changes: 3 additions & 0 deletions br/tests/br_table_partition/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,13 @@ done
wait

run_sql "ALTER TABLE $DB.${TABLE}_Hash ADD UNIQUE INDEX idx(c1) GLOBAL" &
run_sql "ALTER TABLE $DB.${TABLE}_Hash ADD INDEX idx1(c1) GLOBAL" &
run_sql "ALTER TABLE $DB.${TABLE}_List ADD UNIQUE INDEX idx(c1) GLOBAL" &
run_sql "ALTER TABLE $DB.${TABLE}_List ADD INDEX idx1(c1) GLOBAL" &

for i in $(seq $TABLE_COUNT); do
run_sql "ALTER TABLE $DB.$TABLE${i} ADD UNIQUE INDEX idx(c1) GLOBAL" &
run_sql "ALTER TABLE $DB.$TABLE${i} ADD INDEX idx1(c1) GLOBAL" &
done
wait

10 changes: 8 additions & 2 deletions br/tests/br_table_partition/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ DB=$DB TABLE=$TABLE TABLE_COUNT=$TABLE_COUNT prepare.sh

declare -A row_count_ori
declare -A row_count_new
declare -A row_count_new_global_index
declare -A row_count_new_non_unique_global_index

for i in $(seq $TABLE_COUNT) _Hash _List; do
row_count_ori[$i]=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE${i};" | awk '/COUNT/{print $2}')
Expand All @@ -44,15 +46,19 @@ run_br restore full -s "local://$TEST_DIR/$DB" --pd $PD_ADDR
for i in $(seq $TABLE_COUNT) _Hash _List; do
run_sql "SHOW CREATE TABLE $DB.$TABLE${i};" | grep 'PARTITION'
row_count_new[$i]=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE${i};" | awk '/COUNT/{print $2}')
row_count_new_global_index[$i]=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE${i} use index(idx);" | awk '/COUNT/{print $2}')
row_count_new_non_unique_global_index[$i]=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE${i} use index(idx1);" | awk '/COUNT/{print $2}')
done

fail=false
for i in $(seq $TABLE_COUNT) _Hash _List; do
if [ "${row_count_ori[$i]}" != "${row_count_new[$i]}" ];then
if [ "${row_count_ori[$i]}" != "${row_count_new[$i]}" ] || \
[ "${row_count_ori[$i]}" != "${row_count_new_global_index[$i]}" ] || \
[ "${row_count_ori[$i]}" != "${row_count_new_non_unique_global_index[$i]}" ]; then
fail=true
echo "TEST: [$TEST_NAME] fail on table $DB.$TABLE${i}"
fi
echo "table $DB.$TABLE${i} [original] row count: ${row_count_ori[$i]}, [after br] row count: ${row_count_new[$i]}"
echo "table $DB.$TABLE${i} [original] row count: ${row_count_ori[$i]}, [after br] row count: ${row_count_new[$i]}, global index row count: ${row_count_new_global_index[$i]}, non-unique global index row count: ${row_count_new_non_unique_global_index[$i]}"
done

if $fail; then
Expand Down
2 changes: 1 addition & 1 deletion dumpling/tests/partition_table/data/pt_case_0.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
create table `pt_case_0` (a int, b int, unique index idx(a) global) partition by hash(b) partitions 5;
create table `pt_case_0` (a int, b int, unique index idx(a) global, index idx1(a) global) partition by hash(b) partitions 5;
insert into `pt_case_0` values
(0, 10),
(1, 9),
Expand Down
2 changes: 1 addition & 1 deletion dumpling/tests/partition_table/data/pt_case_1.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
create table `pt_case_1` (a int, b int, unique index idx(a) global) partition by list(b)
create table `pt_case_1` (a int, b int, unique index idx(a) global, index idx1(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));
Expand Down
2 changes: 1 addition & 1 deletion dumpling/tests/partition_table/data/pt_case_2.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
create table `pt_case_2` (a int, b int, unique index idx(a) global) partition by range(b)
create table `pt_case_2` (a int, b int, unique index idx(a) global, index idx1(a) global) partition by range(b)
(partition p0 values less than (4),
partition p1 values less than (7),
partition p2 values less than (11));
Expand Down
3 changes: 2 additions & 1 deletion dumpling/tests/partition_table/result/pt_case_0-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
CREATE TABLE `pt_case_0` (
`a` int DEFAULT NULL,
`b` int DEFAULT NULL,
UNIQUE KEY `idx` (`a`) /*T![global_index] GLOBAL */
UNIQUE KEY `idx` (`a`) /*T![global_index] GLOBAL */,
KEY `idx1` (`a`) /*T![global_index] GLOBAL */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY HASH (`b`) PARTITIONS 5;
3 changes: 2 additions & 1 deletion dumpling/tests/partition_table/result/pt_case_1-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
CREATE TABLE `pt_case_1` (
`a` int DEFAULT NULL,
`b` int DEFAULT NULL,
UNIQUE KEY `idx` (`a`) /*T![global_index] GLOBAL */
UNIQUE KEY `idx` (`a`) /*T![global_index] GLOBAL */,
KEY `idx1` (`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),
Expand Down
3 changes: 2 additions & 1 deletion dumpling/tests/partition_table/result/pt_case_2-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
CREATE TABLE `pt_case_2` (
`a` int DEFAULT NULL,
`b` int DEFAULT NULL,
UNIQUE KEY `idx` (`a`) /*T![global_index] GLOBAL */
UNIQUE KEY `idx` (`a`) /*T![global_index] GLOBAL */,
KEY `idx1` (`a`) /*T![global_index] GLOBAL */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY RANGE (`b`)
(PARTITION `p0` VALUES LESS THAN (4),
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
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;
create table a (a int, b varchar(16), c int, KEY key_b (`b`), unique index key_c(`c`) global, index key_a(`a`) global) partition by hash(a) partitions 5;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
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));
create table `defaultlist` (a int, b varchar(16), c int, KEY key_b (`b`), unique index key_c(`c`) global, index key_a(`a`) 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 +1 @@
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));
create table `list` (a int, b varchar(16), c int, KEY key_b (`b`), unique index key_c(`c`) global, index key_a(`a`) 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 +1 @@
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));
create table `range` (a int, b varchar(16), c int, KEY key_b (`b`), unique index key_c(`c`) global, index key_a(`a`) global) partition by range(a) (partition pNeg values less than (0), partition pMax values less than (maxvalue));
24 changes: 20 additions & 4 deletions lightning/tests/lightning_partitioned-table/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,47 +27,63 @@ for BACKEND in tidb local; do

run_lightning --backend $BACKEND

run_sql 'SELECT count(1), sum(a) FROM partitioned.a;'
run_sql 'SELECT count(1), sum(a) FROM partitioned.a use index ();'
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 'SELECT count(1), sum(a) FROM partitioned.a use index (key_a);'
check_contains 'count(1): 8'
check_contains 'sum(a): 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;'
run_sql 'SELECT count(1), sum(a) FROM partitioned.range use index ();'
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 'SELECT count(1), sum(a) FROM partitioned.range use index (key_a);'
check_contains 'count(1): 8'
check_contains 'sum(a): 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;'
run_sql 'SELECT count(1), sum(a) FROM partitioned.list use index ();'
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 'SELECT count(1), sum(a) FROM partitioned.list use index (key_a);'
check_contains 'count(1): 8'
check_contains 'sum(a): 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;'
run_sql 'SELECT count(1), sum(a) FROM partitioned.defaultlist use index ();'
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 'SELECT count(1), sum(a) FROM partitioned.defaultlist use index (key_a);'
check_contains 'count(1): 8'
check_contains 'sum(a): 277151781'

run_sql "SHOW TABLE STATUS FROM partitioned WHERE name = 'defaultlist';"
check_contains 'Create_options: partitioned'
done
14 changes: 14 additions & 0 deletions tests/realtikvtest/importintotest/import_into_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,20 @@ func (s *mockGCSSuite) TestBasicImportInto() {
querySQL: "select * from t order by b",
lastInsertID: 6,
},
// partition table
{
createTableSQL: "create table t (a bigint, b varchar(100), c int) partition by hash(a) partitions 5;",
flags: "(c, b, a)",
res: []string{"11 test1 1", "22 test2 2", "33 test3 3", "44 test4 4", "55 test5 5", "66 test6 6"},
querySQL: "select * from t order by c",
},
// partition table + global index
{
createTableSQL: "create table t (a bigint, b varchar(100), c int, index idx(c) global) partition by hash(a) partitions 5;",
flags: "(c, b, a)",
res: []string{"11 test1 1", "22 test2 2", "33 test3 3", "44 test4 4", "55 test5 5", "66 test6 6"},
querySQL: "select * from t use index(idx) order by c",
},
}

loadDataSQL := fmt.Sprintf(`import into t %%s FROM 'gs://test-multi-load/db.tbl.*.csv?endpoint=%s'
Expand Down

0 comments on commit 2fafd20

Please sign in to comment.