Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

br: add integration test for pitr to test compatibility between pitr and accelerate indexing #51988

Merged
merged 8 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions br/tests/br_pitr/check/check_ingest_repair.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash
#
# Copyright 2023 PingCAP, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Copyright 2023 PingCAP, Inc.
# Copyright 2024 PingCAP, Inc.

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -eu
# check index schema
## check table test.pairs
run_sql "SHOW INDEX FROM test.pairs WHERE Key_name = 'i1' AND Index_type = 'HASH' AND Index_comment = 'edelw;fe?fewfe\nefwe' AND Visible = 'NO';"
check_contains "Column_name: y"
check_contains "Column_name: z"

run_sql "SHOW INDEX FROM test.pairs WHERE Key_name = 'u1' AND Index_type = 'RTREE' AND Index_comment = '' AND Visible = 'YES';"
check_contains "Column_name: x"
check_contains "Column_name: y"

run_sql "SHOW INDEX FROM test.pairs WHERE Key_name = 'i2' AND Index_type = 'BTREE' AND Index_comment = '123' AND Visible = 'YES';"
check_contains "Column_name: y"
check_contains "Expression: \`z\` + 1"

run_sql "SHOW INDEX FROM test.pairs WHERE Key_name = 'u2' AND Index_type = 'HASH' AND Index_comment = '243' AND Visible = 'YES';"
check_contains "Column_name: x"
check_contains "Expression: \`y\` + 1"

## check table test.pairs2
run_sql "SHOW INDEX FROM test.pairs2 WHERE Key_name = 'i1' AND Visible = 'YES';"
check_contains "Column_name: y"
check_contains "Column_name: z"
run_sql "SHOW INDEX FROM test.pairs2 WHERE Column_name = 'z' AND Key_name = 'i1' AND Visible = 'YES';"
check_contains "Sub_part: 10"

run_sql "SHOW INDEX FROM test.pairs2 WHERE Key_name = 'u1' AND Index_type = 'RTREE' AND Visible = 'YES';"
check_contains "Column_name: y"
check_contains "Column_name: z"
check_contains "Expression: \`y\` * 2"
run_sql "SHOW INDEX FROM test.pairs2 WHERE Column_name = 'z' AND Key_name = 'u1' AND Index_type = 'RTREE' AND Visible = 'YES';"
check_contains "Sub_part: 10"

run_sql "SHOW INDEX FROM test.pairs2 WHERE Key_name = 'PRIMARY' AND Index_type = 'HASH' AND Visible = 'YES';"
check_contains "Column_name: x"

## check table test.pairs3
run_sql "SHOW INDEX FROM test.pairs3 WHERE Key_name = 'zips2' AND Index_type = 'BTREE' AND Visible = 'YES';"
check_contains "Expression: cast(json_extract(\`custinfo\`, _utf8'$.zipcode') as unsigned array)"

## check table test.pairs4
run_sql "SHOW INDEX FROM test.pairs4 WHERE Key_name != 'PRIMARY';"
check_not_contains "1. row" ## the result should be empty

## check table test.pairs5
run_sql "SHOW INDEX FROM test.pairs5;"
check_not_contains "1. row" ## the result should be empty

## check table test.pairs7
run_sql "SHOW INDEX FROM test.pairs7 WHERE Key_name = 'zips2' AND Visible = 'YES';"
check_contains "Expression: cast(json_extract(\`cust\`\`;info\`, _utf8'$.zipcode') as unsigned array)"
run_sql "SHOW INDEX FROM test.pairs7 WHERE Key_name = 'i2' AND Seq_in_index = 1 AND Visible = 'YES';"
check_contains "Column_name: nam\`;e"
run_sql "SHOW INDEX FROM test.pairs7 WHERE Key_name = 'i2' AND Seq_in_index = 2 AND Visible = 'YES';"
check_contains "Expression: \`nam\`\`;e\` * 2"

## check table test.pairs11
run_sql "SELECT count(*) AS RESCNT FROM INFORMATION_SCHEMA.TIDB_INDEXES WHERE INDEX_ID = 1 AND TABLE_NAME = 'pairs11' AND KEY_NAME = 'u1';"
check_contains "RESCNT: 2"

# adjust some index to be visible
run_sql "ALTER TABLE test.pairs ALTER INDEX i1 VISIBLE;"

# check index data
run_sql "select count(*) AS RESCNT from test.pairs use index(i1) where y = 0 and z = 0;"
check_not_contains "RESCNT: 0"
run_sql "select count(*) AS RESCNT from test.pairs use index(u1) where x = 1 and y = 0;"
check_not_contains "RESCNT: 0"
run_sql "select count(*) AS RESCNT from test.pairs use index(i2) where y = 1 and z+1 = 1;"
check_not_contains "RESCNT: 0"
run_sql "select count(*) AS RESCNT from test.pairs use index(u2) where x = 1 and y+1 = 1;"
check_not_contains "RESCNT: 0"
run_sql "select count(*) AS RESCNT from test.pairs2 use index(i1) where y = 1 and z = '1';"
check_not_contains "RESCNT: 0"
run_sql "select count(*) AS RESCNT from test.pairs2 use index(u1) where y = 1 and z = '1' and y*2=2;"
check_not_contains "RESCNT: 0"
run_sql "select count(*) AS RESCNT from test.pairs2 use index(PRIMARY) where x = 1;"
check_not_contains "RESCNT: 0"
run_sql "select count(*) AS RESCNT from test.pairs3 use index(zips2) where custinfo->'$.zipcode' = json_array(1,2);"
check_not_contains "RESCNT: 0"
run_sql "select count(*) AS RESCNT from test.pairs7 use index(zips2) where \`cust\`\`;info\`->'$.zipcode' =json_array(1,2);"
check_not_contains "RESCNT: 0"
run_sql "select count(*) AS RESCNT from test.pairs7 use index(i2) where \`nam\`\`;e\` = 1 and \`nam\`\`;e\` * 2 = 2;"
check_not_contains "RESCNT: 0"
run_sql "select count(*) AS RESCNT from test.pairs8 use index(i1) where y = '1';"
check_not_contains "RESCNT: 0"
run_sql "select count(*) AS RESCNT from test.pairs9 use index(i1) where y2 = '1';"
check_not_contains "RESCNT: 0"
run_sql "select count(*) AS RESCNT from test.pairs10 use index(i1) where y = 1;"
check_not_contains "RESCNT: 0"
run_sql "select count(*) AS RESCNT from test.pairs10 use index(i1) where y = 101;"
check_not_contains "RESCNT: 0"
run_sql "select count(*) AS RESCNT from test.pairs10 use index(i1) where y = 201;"
check_not_contains "RESCNT: 0"
48 changes: 48 additions & 0 deletions br/tests/br_pitr/incremental_data/ingest_repair.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
-- basic test: [INDEX/UNIQUE], [COMMENT], [INDEXTYPE], [INVISIBLE], [EXPRESSION]
ALTER TABLE test.pairs ADD INDEX i1(y, z) USING HASH COMMENT "edelw;fe?fewfe\nefwe" INVISIBLE;
ALTER TABLE test.pairs ADD UNIQUE KEY u1(x, y) USING RTREE VISIBLE;
ALTER TABLE test.pairs ADD INDEX i2(y, (z + 1)) USING BTREE COMMENT "123";
ALTER TABLE test.pairs ADD UNIQUE KEY u2(x, (y+1)) USING HASH COMMENT "243";

-- test: [COLUMN LENGTH], [EXPRESSION], [PRIMARY]
ALTER TABLE test.pairs2 ADD INDEX i1(y, z(10));
ALTER TABLE test.pairs2 ADD UNIQUE KEY u1(y, z(10), (y * 2)) USING RTREE VISIBLE;
ALTER TABLE test.pairs2 ADD PRIMARY KEY (x) USING HASH;

-- test: [MULTIVALUED]
ALTER TABLE test.pairs3 ADD INDEX zips2((CAST(custinfo->'$.zipcode' AS UNSIGNED ARRAY)));

-- test: DROP operation
ALTER TABLE test.pairs4 ADD INDEX i1(y, z) USING HASH COMMENT "edelw;fe?fewfe\nefwe" INVISIBLE;
ALTER TABLE test.pairs4 ADD UNIQUE KEY u1(x, y) USING RTREE VISIBLE;
ALTER TABLE test.pairs4 ADD INDEX i2(y, (z + 1)) USING BTREE COMMENT "123";
ALTER TABLE test.pairs4 ADD UNIQUE KEY u2(x, (y+1)) USING HASH COMMENT "243";
ALTER TABLE test.pairs4 DROP INDEX i1;
ALTER TABLE test.pairs4 DROP INDEX u1;
ALTER TABLE test.pairs4 DROP INDEX i2;
ALTER TABLE test.pairs4 DROP INDEX u2;

-- test: DROP operation
ALTER TABLE test.pairs5 ADD INDEX i1(y, z(10));
ALTER TABLE test.pairs5 ADD UNIQUE KEY u1(y, z(10), (y * 2)) USING RTREE VISIBLE;
ALTER TABLE test.pairs5 ADD PRIMARY KEY (x) USING HASH;
ALTER TABLE test.pairs5 DROP INDEX i1;
ALTER TABLE test.pairs5 DROP INDEX u1;
ALTER TABLE test.pairs5 DROP INDEX `PRIMARY`;

-- test: [strange string in EXPRESSION], [rename operation]
ALTER TABLE test.pairs6 ADD INDEX zips2((CAST(`cust``;info`->'$.zipcode' AS UNSIGNED ARRAY)));
ALTER TABLE test.pairs6 ADD INDEX i1(`nam``;e`, (`nam``;e` * 2));
RENAME TABLE test.pairs6 TO test.pairs7;
ALTER TABLE test.pairs7 RENAME INDEX i1 to i2;

-- future test: [MODIFY COLUMN operation]
ALTER TABLE test.pairs8 ADD INDEX i1(y);
ALTER TABLE test.pairs8 MODIFY y varchar(20);

-- future test: [CHANGE COLUMN operation]
ALTER TABLE test.pairs9 ADD INDEX i1(y);
ALTER TABLE test.pairs9 CHANGE y y2 varchar(20);

-- test partition
ALTER TABLE test.pairs10 ADD INDEX i1(y);
Loading