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

lightning: fix cluster index #39010

Merged
merged 13 commits into from
Nov 10, 2022
9 changes: 6 additions & 3 deletions br/pkg/lightning/restore/meta_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1186,9 +1186,12 @@ func getGlobalAutoIDAlloc(store kv.Storage, dbID int64, tblInfo *model.TableInfo
return nil, errors.New("internal error: dbID should not be 0")
}

// We don't need the cache here because we allocate all IDs at once.
// The argument for CustomAutoIncCacheOption is the cache step. step 1 means no cache.
noCache := autoid.CustomAutoIncCacheOption(1)
// We don't need autoid cache here because we allocate all IDs at once.
// The argument for CustomAutoIncCacheOption is the cache step. Step 1 means no cache,
// but step 1 will enable an experimental feature, so we use step 2 here.
//
// See https://github.com/pingcap/tidb/issues/38442 for more details.
noCache := autoid.CustomAutoIncCacheOption(2)
tblVer := autoid.AllocOptionTableInfoVersion(tblInfo.Version)

hasRowID := common.TableHasAutoRowID(tblInfo)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
create table `exotic``table````name` (a varchar(6) primary key, b int unique auto_increment) auto_increment=80000;
create table `exotic``table````name` (a varchar(6) primary key /*T![clustered_index] NONCLUSTERED */, b int unique auto_increment) auto_increment=80000;
Original file line number Diff line number Diff line change
@@ -1 +1 @@
create table 中文表(a int primary key);
create table 中文表(a int primary key /*T![clustered_index] NONCLUSTERED */);
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ CREATE TABLE `test` (
`s1` char(10) NOT NULL,
`s2` char(10) NOT NULL,
`s3` char(10) DEFAULT NULL,
PRIMARY KEY (`s1`,`s2`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin/*!90000 SHARD_ROW_ID_BITS=3 PRE_SPLIT_REGIONS=3 */;
PRIMARY KEY (`s1`,`s2`) /*T![clustered_index] NONCLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin/*!90000 SHARD_ROW_ID_BITS=3 PRE_SPLIT_REGIONS=3 */;
2 changes: 1 addition & 1 deletion br/tests/lightning_tidb_rowid/data/rowid.non_pk-schema.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
create table non_pk (pk varchar(6) primary key);
create table non_pk (pk varchar(6) primary key /*T![clustered_index] NONCLUSTERED */);
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
CREATE TABLE `non_pk_auto_inc` (
`pk` char(36) NOT NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`pk`),
PRIMARY KEY (`pk`) /*T![clustered_index] NONCLUSTERED */,
UNIQUE KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;