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

pitr: add ingest recorder to repair indexes (#41670) #46418

Merged

Conversation

ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #41670

What problem does this PR solve?

Issue Number: close #41668 ref #38045

Problem Summary:
PiTR is not compatible with accelerated indexing

What is changed and how it works?

  1. record the ingest indexes from history ddl
  2. drop the indexes
  3. re-add the indexes

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

upstream SQL

CREATE TABLE test.pairs(x int auto_increment primary key, y int DEFAULT RAND(), z int DEFAULT RAND());
INSERT INTO test.pairs VALUES (), ... (skip 500), ();
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";

CREATE TABLE test.pairs2(x int, y int, z varchar(20));
INSERT INTO test.pairs2 VALUES (1,1,"1"), ... (skip 500), (500,500,"500");
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;

CREATE TABLE test.pairs3(id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, name CHAR(10), custinfo JSON);
INSERT INTO test.pairs3 VALUES (1, 'pingcap', '{"zipcode": [1,2]}');
ALTER TABLE test.pairs3 ADD INDEX zips2((CAST(custinfo->'$.zipcode' AS UNSIGNED ARRAY)));

CREATE TABLE test.pairs4(x int auto_increment primary key, y int DEFAULT RAND(), z int DEFAULT RAND());
INSERT INTO test.pairs4 VALUES (), ... (skip 500), ();
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;

CREATE TABLE test.pairs5(x int, y int, z varchar(20));
INSERT INTO test.pairs5 VALUES (1,1,"1"), ... (skip 500), (500,500,"500");
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`;

CREATE TABLE test.pairs6(id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, `nam``;e` int, `cust``;info` JSON);
INSERT INTO test.pairs6 VALUES (1, 1, '{"zipcode": [1,2]}');
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;

restore repair ingest index SQL from BR log

ALTER TABLE `test`.`pairs` DROP INDEX `i1`
ALTER TABLE `test`.`pairs` ADD INDEX `i1`(`y`,`z`) USING HASH COMMENT 'edelw;fe?fewfe\\nefwe' INVISIBLE
ALTER TABLE `test`.`pairs` DROP INDEX `u1`
ALTER TABLE `test`.`pairs` ADD UNIQUE KEY `u1`(`x`,`y`) USING RTREE VISIBLE
ALTER TABLE `test`.`pairs` DROP INDEX `i2`
ALTER TABLE `test`.`pairs` ADD INDEX `i2`(`y`,(`z` + 1)) USING BTREE COMMENT '123' VISIBLE
ALTER TABLE `test`.`pairs` DROP INDEX `u2`
ALTER TABLE `test`.`pairs` ADD UNIQUE KEY `u2`(`x`,(`y` + 1)) USING HASH COMMENT '243' VISIBLE
ALTER TABLE `test`.`pairs2` DROP INDEX `PRIMARY`
ALTER TABLE `test`.`pairs2` ADD PRIMARY KEY (`x`) NONCLUSTERED USING HASH VISIBLE
ALTER TABLE `test`.`pairs2` DROP INDEX `i1`
ALTER TABLE `test`.`pairs2` ADD INDEX `i1`(`y`,`z`(10)) USING BTREE VISIBLE
ALTER TABLE `test`.`pairs2` DROP INDEX `u1`
ALTER TABLE `test`.`pairs2` ADD UNIQUE KEY `u1`(`y`,`z`(10),(`y` * 2)) USING RTREE VISIBLE
ALTER TABLE `test`.`pairs3` DROP INDEX `zips2`
ALTER TABLE `test`.`pairs3` ADD INDEX `zips2`((cast(json_extract(`custinfo`, _utf8'$.zipcode') as unsigned array))) USING BTREE VISIBLE
ALTER TABLE `test`.`pairs7` DROP INDEX `zips2`
ALTER TABLE `test`.`pairs7` ADD INDEX `zips2`((cast(json_extract(`cust``;info`, _utf8'$.zipcode') as unsigned array))) USING BTREE VISIBLE
ALTER TABLE `test`.`pairs7` DROP INDEX `i2`
ALTER TABLE `test`.`pairs7` ADD INDEX `i2`(`nam``;e`,(`nam``;e` * 2)) USING BTREE VISIBLE

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. type/cherry-pick-for-release-6.5 This PR is cherry-picked to release-6.5 from a source PR. labels Aug 25, 2023
@Leavrth
Copy link
Contributor

Leavrth commented Sep 8, 2023

/retest

@ti-chi-bot ti-chi-bot added the cherry-pick-approved Cherry pick PR approved by release team. label Sep 8, 2023
@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Sep 8, 2023
@codecov
Copy link

codecov bot commented Sep 8, 2023

Codecov Report

❗ No coverage uploaded for pull request base (release-6.5@d7ce2f2). Click here to learn what that means.
The diff coverage is n/a.

Additional details and impacted files
@@               Coverage Diff                @@
##             release-6.5     #46418   +/-   ##
================================================
  Coverage               ?   73.6551%           
================================================
  Files                  ?       1085           
  Lines                  ?     348417           
  Branches               ?          0           
================================================
  Hits                   ?     256627           
  Misses                 ?      75314           
  Partials               ?      16476           
📢 Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pingcap).

@ti-chi-bot
Copy link

ti-chi-bot bot commented Sep 8, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: BornChanger, Leavrth

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm approved and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Sep 8, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Sep 8, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-09-08 04:07:32.382094979 +0000 UTC m=+2677616.931110962: ☑️ agreed by BornChanger.
  • 2023-09-08 05:21:25.498319284 +0000 UTC m=+2682050.047335271: ☑️ agreed by Leavrth.

@ti-chi-bot ti-chi-bot bot merged commit a1af97e into pingcap:release-6.5 Sep 8, 2023
22 checks passed
@Leavrth
Copy link
Contributor

Leavrth commented Sep 8, 2023

/revert

Leavrth added a commit to Leavrth/tidb that referenced this pull request Sep 8, 2023
@ti-chi-bot ti-chi-bot removed the cherry-pick-approved Cherry pick PR approved by release team. label Sep 8, 2023
@ti-chi-bot ti-chi-bot added the cherry-pick-approved Cherry pick PR approved by release team. label Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved cherry-pick-approved Cherry pick PR approved by release team. lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. type/cherry-pick-for-release-6.5 This PR is cherry-picked to release-6.5 from a source PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants