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: Support for showing "AUTO_INCREMENT" in "information_schema.tables" #7037

Merged
merged 3 commits into from
Jul 14, 2018

Conversation

zimulala
Copy link
Contributor

What have you changed? (mandatory)

Fix #6973

tidb>create table t(id int auto_increment primary key, c int);
Query OK, 0 rows affected (0.11 sec)

tidb>insert into t values(1,1);
Query OK, 1 row affected (0.10 sec)

tidb>insert into t values(10000,1);
Query OK, 1 row affected (0.01 sec)

tidb>select * from t;
+-------+------+
| id    | c    |
+-------+------+
|     1 |    1 |
| 10000 |    1 |
+-------+------+
3 rows in set (0.00 sec)

select auto_increment from information_schema.tables where table_name = 't';

before :

+----------------+
| auto_increment |
+----------------+
|             0 |
+----------------+
1 row in set (0.00 sec)

after :

+----------------+
| auto_increment |
+----------------+
|          30002 |
+----------------+
1 row in set (0.00 sec)

What is the type of the changes? (mandatory)

  • Bug fix (non-breaking change which fixes an issue)

How has this PR been tested? (mandatory)

Unit test

Does this PR affect documentation (docs/docs-cn) update? (mandatory)

No

Does this PR affect tidb-ansible update? (mandatory)

No

Does this PR need to be added to the release notes? (mandatory)

release note:
Support for showing "auto_increment" in "information_schema.tables".

@zimulala
Copy link
Contributor Author

/run-all-tests

testkit.Rows("1"))
tk.MustExec("insert into t(c, d) values(1, 1)")
tk.MustQuery("select auto_increment from information_schema.tables where table_name='t'").Check(
testkit.Rows("30002"))
Copy link
Contributor

Choose a reason for hiding this comment

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

why this return 30002?

Copy link
Contributor

Choose a reason for hiding this comment

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

@zimulala Allocate a batch of 30000 AUTO_INCREMENT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@XuHuaiyu
Because the next global auto ID is 30002.
We can do some operations as follows:
TiDB 1

tidb> create table t(`id` int(11) NOT NULL AUTO_INCREMENT,`c` int(11) DEFAULT NULL, PRIMARY KEY (`id`));
Query OK, 0 rows affected (0.13 sec)

tidb> insert into t values(1,1);
Query OK, 1 row affected (0.14 sec)

tidb> insert into t values(10000,1);
Query OK, 1 row affected (0.02 sec)

tidb> select * from t;
+-------+------+
| id    | c    |
+-------+------+
|     1 |    1 |
| 10000 |    1 |
+-------+------+
2 rows in set (0.01 sec)

TiDB 2
Then we do the operation as follows:

tidb> insert into t values();
Query OK, 1 row affected (0.13 sec)

tidb> select * from t;
+-------+------+
| id    | c    |
+-------+------+
|     1 |    1 |
| 10000 |    1 |
| 30002 | NULL |
+-------+------+
3 rows in set (0.01 sec)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ciscoxll
Yes.

hasAutoIncID := false
for _, col := range tblInfo.Cols() {
if mysql.HasAutoIncrementFlag(col.Flag) {
hasAutoIncID = true
Copy link
Contributor

Choose a reason for hiding this comment

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

can break here?

Copy link
Contributor

Choose a reason for hiding this comment

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

@zimulala Please change here.

@zz-jason
Copy link
Member

@zimulala please add the "release-note" label for this PR

@zimulala zimulala added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Jul 12, 2018
@zimulala
Copy link
Contributor Author

PTAL @XuHuaiyu @ciscoxll

@ciscoxll
Copy link
Contributor

LGTM

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason
Copy link
Member

/run-all-tests

@zz-jason zz-jason merged commit 419e5cf into pingcap:master Jul 14, 2018
@zz-jason zz-jason added the status/LGT2 Indicates that a PR has LGTM 2. label Jul 14, 2018
@zimulala zimulala deleted the select-autoIncID branch July 16, 2018 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/execution SIG execution status/LGT2 Indicates that a PR has LGTM 2. type/compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for showing "AUTO_INCREMENT" in "information_schema.tables"
5 participants