-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is an automated cherry-pick of #57303
Signed-off-by: ti-chi-bot <[email protected]>
- Loading branch information
1 parent
a276364
commit c9ab4fc
Showing
8 changed files
with
2,136 additions
and
8 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
drop table if exists t1; | ||
create table t1 (da date default '1962-03-03 23:33:34', dt datetime default '1962-03-03', ti time default '2020-10-11 12:23:23', ts timestamp default '2020-10-13 12:23:23'); | ||
show create table t1; | ||
Table Create Table | ||
t1 CREATE TABLE `t1` ( | ||
`da` date DEFAULT '1962-03-03', | ||
`dt` datetime DEFAULT '1962-03-03 00:00:00', | ||
`ti` time DEFAULT '12:23:23', | ||
`ts` timestamp DEFAULT '2020-10-13 12:23:23' | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin | ||
insert into t1 values(); | ||
select * from t1; | ||
da dt ti ts | ||
1962-03-03 1962-03-03 00:00:00 12:23:23 2020-10-13 12:23:23 | ||
alter table t1 add column da1 date default '2020-03-27 20:20:20 123456'; | ||
show create table t1; | ||
Table Create Table | ||
t1 CREATE TABLE `t1` ( | ||
`da` date DEFAULT '1962-03-03', | ||
`dt` datetime DEFAULT '1962-03-03 00:00:00', | ||
`ti` time DEFAULT '12:23:23', | ||
`ts` timestamp DEFAULT '2020-10-13 12:23:23', | ||
`da1` date DEFAULT '2020-03-27' | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin | ||
select * from t1; | ||
da dt ti ts da1 | ||
1962-03-03 1962-03-03 00:00:00 12:23:23 2020-10-13 12:23:23 2020-03-27 | ||
alter table t1 change ts da2 date default '2020-10-10 20:20:20'; | ||
show create table t1; | ||
Table Create Table | ||
t1 CREATE TABLE `t1` ( | ||
`da` date DEFAULT '1962-03-03', | ||
`dt` datetime DEFAULT '1962-03-03 00:00:00', | ||
`ti` time DEFAULT '12:23:23', | ||
`da2` date DEFAULT '2020-10-10', | ||
`da1` date DEFAULT '2020-03-27' | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin | ||
select * from t1; | ||
da dt ti da2 da1 | ||
1962-03-03 1962-03-03 00:00:00 12:23:23 2020-10-13 2020-03-27 | ||
drop table if exists t1, t2; | ||
CREATE TABLE t1(id INTEGER PRIMARY KEY, authorId INTEGER AUTO_INCREMENT UNIQUE); | ||
show create table t1; | ||
Table Create Table | ||
t1 CREATE TABLE `t1` ( | ||
`id` int NOT NULL, | ||
`authorId` int NOT NULL AUTO_INCREMENT, | ||
PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */, | ||
UNIQUE KEY `authorId` (`authorId`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin | ||
CREATE TABLE `t2`( `id` INTEGER PRIMARY KEY, `authorId` int(11) AUTO_INCREMENT, UNIQUE KEY `authorIdx` (`authorId`)); | ||
show create table t2; | ||
Table Create Table | ||
t2 CREATE TABLE `t2` ( | ||
`id` int NOT NULL, | ||
`authorId` int NOT NULL AUTO_INCREMENT, | ||
PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */, | ||
UNIQUE KEY `authorIdx` (`authorId`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin | ||
set @@sql_mode=''; | ||
drop table if exists t1; | ||
create table t1(b tinyint default '11111111'); | ||
Error 1067 (42000): Invalid default value for 'b' | ||
create table t1(b tinyint default '11abc'); | ||
Error 1067 (42000): Invalid default value for 'b' | ||
create table t1(b datetime default '11abc'); | ||
Error 1067 (42000): Invalid default value for 'b' | ||
create table t1(b date default '2024-10'); | ||
Error 1067 (42000): Invalid default value for 'b' | ||
create table t1(a tinyint, b date default '2024-10-24 12:20'); | ||
alter table t1 add column(c tinyint default '11111111'); | ||
Error 1067 (42000): Invalid default value for 'c' | ||
alter table t1 add column(c tinyint default '11abc'); | ||
Error 1067 (42000): Invalid default value for 'c' | ||
alter table t1 add column(c datetime default '11abc'); | ||
Error 1067 (42000): Invalid default value for 'c' | ||
alter table t1 add column d date default '2024-10'; | ||
Error 1067 (42000): Invalid default value for 'd' | ||
drop table if exists t; | ||
create table t(a decimal(0,0), b decimal(0)); | ||
show create table t; | ||
Table Create Table | ||
t CREATE TABLE `t` ( | ||
`a` decimal(10,0) DEFAULT NULL, | ||
`b` decimal(10,0) DEFAULT NULL | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin | ||
drop table if exists t; | ||
create table t(a bit(2) default b'111'); | ||
Error 1067 (42000): Invalid default value for 'a' | ||
create table t(a bit(65) default b'111'); | ||
Error 1439 (42000): Display width out of range for column 'a' (max = 64) | ||
create table t(a bit(64) default b'1111111111111111111111111111111111111111111111111111111111111111'); | ||
drop table t; | ||
create table t(a bit(3) default b'111'); | ||
drop table t; | ||
create table t(a bit(3) default b'000111'); | ||
drop table t; | ||
create table t(a bit(32) default b'1111111111111111111111111111111'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
drop table if exists shard_t; | ||
create table shard_t (a int) shard_row_id_bits = 15; | ||
set @@tidb_shard_allocate_step=3; | ||
insert into shard_t values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11); | ||
select count(distinct(_tidb_rowid>>48)) from shard_t; | ||
count(distinct(_tidb_rowid>>48)) | ||
4 | ||
truncate table shard_t; | ||
set @@tidb_shard_allocate_step=5; | ||
begin; | ||
insert into shard_t values (1), (2), (3); | ||
insert into shard_t values (4), (5), (6); | ||
insert into shard_t values (7), (8), (9); | ||
insert into shard_t values (10); | ||
commit; | ||
select count(distinct(_tidb_rowid>>48)) from shard_t; | ||
count(distinct(_tidb_rowid>>48)) | ||
2 | ||
truncate table shard_t; | ||
insert into shard_t values (10); | ||
insert into shard_t values (11); | ||
insert into shard_t values (12); | ||
select count(distinct(_tidb_rowid>>48)) from shard_t; | ||
count(distinct(_tidb_rowid>>48)) | ||
3 | ||
set @@tidb_shard_allocate_step=default; | ||
drop table if exists t; | ||
create table t(a bit(32) default b'1100010001001110011000100100111'); | ||
insert into t values (); | ||
select hex(a) from t; | ||
hex(a) | ||
62273127 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# TestGetDefaultValueOfColumn | ||
drop table if exists t1; | ||
create table t1 (da date default '1962-03-03 23:33:34', dt datetime default '1962-03-03', ti time default '2020-10-11 12:23:23', ts timestamp default '2020-10-13 12:23:23'); | ||
show create table t1; | ||
insert into t1 values(); | ||
select * from t1; | ||
alter table t1 add column da1 date default '2020-03-27 20:20:20 123456'; | ||
show create table t1; | ||
select * from t1; | ||
alter table t1 change ts da2 date default '2020-10-10 20:20:20'; | ||
show create table t1; | ||
select * from t1; | ||
|
||
# TestIssue39080 | ||
drop table if exists t1, t2; | ||
CREATE TABLE t1(id INTEGER PRIMARY KEY, authorId INTEGER AUTO_INCREMENT UNIQUE); | ||
show create table t1; | ||
CREATE TABLE `t2`( `id` INTEGER PRIMARY KEY, `authorId` int(11) AUTO_INCREMENT, UNIQUE KEY `authorIdx` (`authorId`)); | ||
show create table t2; | ||
|
||
# TestIssue52972 | ||
# Test creating columns with error defaults when sql_mode is empty. | ||
set @@sql_mode=''; | ||
drop table if exists t1; | ||
--error 1067 | ||
create table t1(b tinyint default '11111111'); | ||
--error 1067 | ||
create table t1(b tinyint default '11abc'); | ||
--error 1067 | ||
create table t1(b datetime default '11abc'); | ||
--error 1067 | ||
create table t1(b date default '2024-10'); | ||
create table t1(a tinyint, b date default '2024-10-24 12:20'); | ||
--error 1067 | ||
alter table t1 add column(c tinyint default '11111111'); | ||
--error 1067 | ||
alter table t1 add column(c tinyint default '11abc'); | ||
--error 1067 | ||
alter table t1 add column(c datetime default '11abc'); | ||
--error 1067 | ||
alter table t1 add column d date default '2024-10'; | ||
|
||
# TestIssue53779 | ||
drop table if exists t; | ||
create table t(a decimal(0,0), b decimal(0)); | ||
show create table t; | ||
|
||
# TestTooLongDefaultValueForBit | ||
drop table if exists t; | ||
-- error 1067 | ||
create table t(a bit(2) default b'111'); | ||
-- error 1439 | ||
create table t(a bit(65) default b'111'); | ||
create table t(a bit(64) default b'1111111111111111111111111111111111111111111111111111111111111111'); | ||
drop table t; | ||
create table t(a bit(3) default b'111'); | ||
drop table t; | ||
create table t(a bit(3) default b'000111'); | ||
drop table t; | ||
create table t(a bit(32) default b'1111111111111111111111111111111'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# TestShardRowIDBitsStep | ||
drop table if exists shard_t; | ||
create table shard_t (a int) shard_row_id_bits = 15; | ||
set @@tidb_shard_allocate_step=3; | ||
insert into shard_t values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11); | ||
select count(distinct(_tidb_rowid>>48)) from shard_t; | ||
|
||
truncate table shard_t; | ||
set @@tidb_shard_allocate_step=5; | ||
begin; | ||
insert into shard_t values (1), (2), (3); | ||
insert into shard_t values (4), (5), (6); | ||
insert into shard_t values (7), (8), (9); | ||
insert into shard_t values (10); | ||
commit; | ||
select count(distinct(_tidb_rowid>>48)) from shard_t; | ||
|
||
truncate table shard_t; | ||
insert into shard_t values (10); | ||
insert into shard_t values (11); | ||
insert into shard_t values (12); | ||
select count(distinct(_tidb_rowid>>48)) from shard_t; | ||
|
||
set @@tidb_shard_allocate_step=default; | ||
|
||
# TestInsertBitDefaultValue | ||
drop table if exists t; | ||
create table t(a bit(32) default b'1100010001001110011000100100111'); | ||
insert into t values (); | ||
select hex(a) from t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters