*: add test cases for non-unique global index (#59012)

ref pingcap/tidb#58650
This commit is contained in:
Hangjie Mo
2025-01-17 17:55:22 +08:00
committed by GitHub
parent db7843a5c4
commit 2fafd20054
14 changed files with 58 additions and 16 deletions

View File

@ -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

View File

@ -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}')
@ -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

View File

@ -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),

View File

@ -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));

View File

@ -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));

View File

@ -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;

View File

@ -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),

View File

@ -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),

View File

@ -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;

View File

@ -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));

View File

@ -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));

View File

@ -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));

View File

@ -27,7 +27,7 @@ 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'
@ -35,10 +35,14 @@ for BACKEND in tidb local; do
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'
@ -46,10 +50,14 @@ for BACKEND in tidb local; do
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'
@ -57,10 +65,14 @@ for BACKEND in tidb local; do
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'
@ -68,6 +80,10 @@ for BACKEND in tidb local; do
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

View File

@ -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'