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

executor, session: refine insert unsigned bigint autoIncreID #8181

Merged
merged 24 commits into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a7df24d
executor, session: refine insert unsigned bigint autoIncreID
XuHuaiyu Nov 5, 2018
9d21807
address comment
XuHuaiyu Nov 8, 2018
2db694e
update parser
XuHuaiyu Nov 12, 2018
1eb9325
Merge branch 'master' of https://github.com/pingcap/tidb into unsigne…
XuHuaiyu Nov 12, 2018
53fd0a6
address comment
XuHuaiyu Nov 12, 2018
758fd31
address comment
XuHuaiyu Nov 13, 2018
a68a08d
make golint happy
XuHuaiyu Nov 13, 2018
c1e1ff6
address commen
XuHuaiyu Nov 13, 2018
9104f74
Merge branch 'master' of https://github.com/pingcap/tidb into unsigne…
XuHuaiyu Nov 16, 2018
fc03231
Merge branch 'master' of https://github.com/pingcap/tidb into unsigne…
XuHuaiyu Dec 10, 2018
82b12d5
address comment
XuHuaiyu Dec 10, 2018
2e8b425
remove go.sum
XuHuaiyu Dec 10, 2018
ce0e447
merge master
XuHuaiyu Dec 10, 2018
874ff0b
address comment
XuHuaiyu Dec 13, 2018
d0616ac
Merge branch 'master' into unsigned_autoid
jackysp Dec 17, 2018
6792306
add unit tests for Allocator
XuHuaiyu Dec 18, 2018
46d20a4
Merge branch 'master' of https://github.com/pingcap/tidb into unsigne…
XuHuaiyu Dec 18, 2018
548ea41
Merge branch 'unsigned_autoid' of https://github.com/XuHuaiyu/tidb in…
XuHuaiyu Dec 18, 2018
61bfec6
update go.mod
XuHuaiyu Dec 18, 2018
6c4419c
address comment
XuHuaiyu Dec 18, 2018
3f1fcb4
make tidy
XuHuaiyu Dec 18, 2018
71ea318
go mod tidy
XuHuaiyu Dec 18, 2018
18c62fe
Merge branch 'master' into unsigned_autoid
XuHuaiyu Dec 18, 2018
d688346
Merge branch 'master' into unsigned_autoid
XuHuaiyu Dec 18, 2018
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
16 changes: 13 additions & 3 deletions executor/insert_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,19 @@ func (e *InsertValues) adjustAutoIncrementDatum(d types.Datum, hasValue bool, c
d.SetNull()
}
if !d.IsNull() {
recordID, err = d.ToInt64(e.ctx.GetSessionVars().StmtCtx)
if e.filterErr(err) != nil {
return types.Datum{}, errors.Trace(err)
sc := e.ctx.GetSessionVars().StmtCtx
if mysql.HasUnsignedFlag(c.Flag) {
var uintD types.Datum
uintD, err = d.ConvertTo(sc, &c.FieldType)
if e.filterErr(err) != nil {
return types.Datum{}, err
}
recordID = int64(uintD.GetUint64())
} else {
recordID, err = d.ToInt64(sc)
if e.filterErr(err) != nil {
return types.Datum{}, errors.Trace(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

ConvertTo checks mysql.HasUnsignedFlag, how about:

datum, err := d.ConvertTo(sc, &c.FieldType)
if e.filterErr(err) != nil {
    return types.Datum{}, err
}
recordID = datum.GetInt64()

}
}
// Use the value if it's not null and not 0.
Expand Down
5 changes: 5 additions & 0 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,11 @@ func (s *testSessionSuite) TestAutoIncrementID(c *C) {

tk.MustQuery("select last_insert_id(20)").Check(testkit.Rows(fmt.Sprint(20)))
tk.MustQuery("select last_insert_id()").Check(testkit.Rows(fmt.Sprint(20)))

tk.MustExec("drop table if exists autoid")
tk.MustExec("create table autoid(`auto_inc_id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,UNIQUE KEY `auto_inc_id` (`auto_inc_id`))")
tk.MustExec("insert into autoid values(9223372036854775808);")
tk.MustQuery("select * from autoid").Check(testkit.Rows("9223372036854775808"))
Copy link
Member

Choose a reason for hiding this comment

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

How about insert auto values after this? e.g. insert into autid values ();

Copy link
Member

Choose a reason for hiding this comment

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

mysql> create table autoid(`auto_inc_id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,UNIQUE KEY `auto_inc_id` (`auto_inc_id`));
Query OK, 0 rows affected (0.02 sec)

mysql> insert into autoid values(9223372036854775808);
Query OK, 1 row affected (0.00 sec)

mysql> select * from autoid;
+---------------------+
| auto_inc_id         |
+---------------------+
| 9223372036854775808 |
+---------------------+
1 row in set (0.00 sec)

mysql> insert into autoid values();
Query OK, 1 row affected (0.00 sec)

mysql> select * from autoid;
+---------------------+
| auto_inc_id         |
+---------------------+
| 9223372036854775808 |
|                   2 |
+---------------------+
2 rows in set (0.00 sec)

}

func (s *testSessionSuite) TestAutoIncrementWithRetry(c *C) {
Expand Down