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

infoschema: fix compatibility of auto_increment column value of INFORMATION_SCHEMA.TABLES #10207

Merged
merged 18 commits into from Jul 23, 2019

Conversation

crazycs520
Copy link
Contributor

@crazycs520 crazycs520 commented Apr 20, 2019

What problem does this PR solve?

Fix compatibility of auto_increment column value of INFORMATION_SCHEMA.TABLES.

create table t1 (a int);
create table t (a int auto_increment key);
select table_name, auto_increment from `INFORMATION_SCHEMA`.`TABLES` where `TABLE_NAME` in ('t1','t');

In MySQL:

mysql > select table_name, auto_increment from `INFORMATION_SCHEMA`.`TABLES` where `TABLE_NAME` in ('t1','t');
+------------+----------------+
| table_name | auto_increment |
+------------+----------------+
| t          | 1              |
| t1         | <null>         |
+------------+----------------+

In TiDB:

tidb > select table_name, auto_increment from `INFORMATION_SCHEMA`.`TABLES` where `TABLE_NAME` in ('t1','t');
+------------+----------------+
| table_name | auto_increment |
+------------+----------------+
| t1         | 0              |
| t          | 1              |
+------------+----------------+

after This PR:
TiDB

create table t1 (a int,b int);
create table t (a int auto_increment key, b int);
select table_name, auto_increment from `INFORMATION_SCHEMA`.`TABLES` where `TABLE_NAME` in ('t1','t');
mysql>select table_name, auto_increment from `INFORMATION_SCHEMA`.`TABLES` where `TABLE_NAME` in ('t1','t');
+------------+----------------+
| table_name | auto_increment |
+------------+----------------+
| t1         | <null>         |
| t          | 0              |                    -- attention, this is still not comatible with mysql, this is cause by that tidb have not allocated auto_increate ID,  so the allocator is 0;
+------------+----------------+
2 rows in set
mysql>insert into t1 set b=1;
Query OK, 1 row affected
Time: 0.008s
mysql>insert into t set b=1;
Query OK, 1 row affected
Time: 0.014s
mysql>select table_name, auto_increment from `INFORMATION_SCHEMA`.`TABLES` where `TABLE_NAME` in ('t1','t');
+------------+----------------+
| table_name | auto_increment |
+------------+----------------+
| t1         | <null>         |
| t          | 2              |                          -- after tidb alloc auto_increament later, It will be compatible with mysql to show the next auto_increament.
+------------+----------------+

What is changed and how it works?

Change dataForTables function.

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

Side effects

Related changes

  • Need to cherry-pick to the release branch?

@codecov
Copy link

codecov bot commented Apr 20, 2019

Codecov Report

Merging #10207 into master will increase coverage by 0.4707%.
The diff coverage is n/a.

@@               Coverage Diff               @@
##             master    #10207        +/-   ##
===============================================
+ Coverage   81.2882%   81.759%   +0.4707%     
===============================================
  Files           423       423                
  Lines         90387     92369      +1982     
===============================================
+ Hits          73474     75520      +2046     
+ Misses        11606     11544        -62     
+ Partials       5307      5305         -2

if err != nil {
return 0, err
}
autoIncID, err := tbl.Allocator(ctx).NextGlobalAutoID(tblInfo.ID)
Copy link
Contributor

@winkyao winkyao Apr 22, 2019

Choose a reason for hiding this comment

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

Could we use the nextAutoID in this autoid.allocator of this table, in the memory

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But select table_name, auto_increment from NFORMATION_SCHEMA.TABLES from different-tidb-server will got different value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Copy link
Contributor

@winkyao winkyao left a comment

Choose a reason for hiding this comment

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

LGTM

@zimulala zimulala added the status/LGT1 Indicates that a PR has LGTM 1. label Apr 30, 2019
infoschema/tables.go Outdated Show resolved Hide resolved
@sre-bot sre-bot mentioned this pull request Jul 19, 2019
infoschema/tables.go Outdated Show resolved Hide resolved
zimulala
zimulala previously approved these changes Jul 19, 2019
Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

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

LGTM

@zimulala zimulala added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 19, 2019
@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520
Copy link
Contributor Author

/run-all-tests tidb-test=pr/865

1 similar comment
@crazycs520
Copy link
Contributor Author

/run-all-tests tidb-test=pr/865

@crazycs520
Copy link
Contributor Author

/run-all-tests tidb-test=pr/865

1 similar comment
@crazycs520
Copy link
Contributor Author

/run-all-tests tidb-test=pr/865

@crazycs520
Copy link
Contributor Author

/run-all-tests tidb-test=pr/865

@crazycs520
Copy link
Contributor Author

/run-unit-test tidb-test=pr/865

@sre-bot
Copy link
Contributor

sre-bot commented Jul 24, 2019

cherry pick to release-3.0 in PR #11413

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT2 Indicates that a PR has LGTM 2. type/bug-fix This PR fixes a bug. type/compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants