mirror of
https://github.com/MariaDB/server.git
synced 2025-12-24 11:21:21 +03:00
Fix for bug #5915 "ALTER TABLE behaves differently when converting column
to auto_increment in 4.1". Now we are enforcing NO_AUTO_VALUE_ON_ZERO mode during ALTER TABLE only if we are converting one auto_increment column to another auto_increment column (this also includes most common case when we don't do anything with such column). Also now when we convert some column to TIMESTAMP NOT NULL column with ALTER TABLE we convert NULL values to current timestamp, (as we do this in INSERT). One can still get old behavior by setting system TIMESTAMP variable to 0. mysql-test/r/auto_increment.result: Added tests for ALTER TABLE converting columns containing NULL and 0 values to AUTO_INCREMENT columns. mysql-test/r/type_timestamp.result: Removed test for creation of TIMESTAMP(19) columns (it is 4.0 specific). Added test for ALTER TABLE converting columns containing NULL values to TIMESTAMP columns. mysql-test/t/auto_increment.test: Added tests for ALTER TABLE converting columns containing NULL and 0 values to AUTO_INCREMENT columns. mysql-test/t/type_timestamp.test: Removed test for creation of TIMESTAMP(19) columns (it is 4.0 specific). Added test for ALTER TABLE converting columns containing NULL values to TIMESTAMP columns. sql/field_conv.cc: Fix bug #5915 "ALTER TABLE behaves differently when converting column to auto_increment in 4.1". Also now when we are converting some column to TIMESTAMP column, we are converting NULL values to CURRENT_TIMESTAMP (as it was initially planned). do_copy_timestamp(): Fixed comment. do_copy_next_number(): We should also set auto_increment_field_not_null to FALSE if we have NULL in source field. Copy_field::set(): Moved setting of copy functions for TIMESTAMP and AUTO_INCREMENT fields to proper place (this was dead code before). sql/sql_table.cc: Fix for bug #5915 "ALTER TABLE behaves differently when converting column to auto_increment in 4.1". Instead of always forcing NO_AUTO_VALUE_ON_ZERO in ALTER TABLE it is better to do this only if we are converting one auto_increment column to another auto_increment column (this also includes most common case when we don't do anything with such column).
This commit is contained in:
@@ -289,3 +289,55 @@ a b
|
||||
0 13
|
||||
500 14
|
||||
drop table t1;
|
||||
create table t1 (a bigint);
|
||||
insert into t1 values (1), (2), (3), (NULL), (NULL);
|
||||
alter table t1 modify a bigint not null auto_increment primary key;
|
||||
select * from t1;
|
||||
a
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
drop table t1;
|
||||
create table t1 (a bigint);
|
||||
insert into t1 values (1), (2), (3), (0), (0);
|
||||
alter table t1 modify a bigint not null auto_increment primary key;
|
||||
select * from t1;
|
||||
a
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
drop table t1;
|
||||
create table t1 (a bigint);
|
||||
insert into t1 values (0), (1), (2), (3);
|
||||
set sql_mode=NO_AUTO_VALUE_ON_ZERO;
|
||||
alter table t1 modify a bigint not null auto_increment primary key;
|
||||
set sql_mode= '';
|
||||
select * from t1;
|
||||
a
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
drop table t1;
|
||||
create table t1 (a int auto_increment primary key , b int null);
|
||||
set sql_mode=NO_AUTO_VALUE_ON_ZERO;
|
||||
insert into t1 values (0,1),(1,2),(2,3);
|
||||
select * from t1;
|
||||
a b
|
||||
0 1
|
||||
1 2
|
||||
2 3
|
||||
set sql_mode= '';
|
||||
alter table t1 modify b varchar(255);
|
||||
insert into t1 values (0,4);
|
||||
select * from t1;
|
||||
a b
|
||||
0 1
|
||||
1 2
|
||||
2 3
|
||||
3 4
|
||||
drop table t1;
|
||||
|
||||
@@ -409,15 +409,12 @@ a b
|
||||
NULL NULL
|
||||
NULL 2003-01-01 00:00:00
|
||||
drop table t1;
|
||||
create table t1 (ts timestamp(19));
|
||||
show create table t1;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`ts` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||
set TIMESTAMP=1000000000;
|
||||
insert into t1 values ();
|
||||
create table t1 (a bigint, b bigint);
|
||||
insert into t1 values (NULL, NULL), (20030101000000, 20030102000000);
|
||||
set timestamp=1000000019;
|
||||
alter table t1 modify a timestamp, modify b timestamp;
|
||||
select * from t1;
|
||||
ts
|
||||
2001-09-09 04:46:40
|
||||
a b
|
||||
2001-09-09 04:46:59 2001-09-09 04:46:59
|
||||
2003-01-01 00:00:00 2003-01-02 00:00:00
|
||||
drop table t1;
|
||||
|
||||
@@ -168,3 +168,41 @@ update t1 set a=NULL where b=13;
|
||||
update t1 set a=500 where b=14;
|
||||
select * from t1 order by b;
|
||||
drop table t1;
|
||||
|
||||
#
|
||||
# Test of behavior of ALTER TABLE when coulmn containing NULL or zeroes is
|
||||
# converted to AUTO_INCREMENT column
|
||||
#
|
||||
create table t1 (a bigint);
|
||||
insert into t1 values (1), (2), (3), (NULL), (NULL);
|
||||
alter table t1 modify a bigint not null auto_increment primary key;
|
||||
select * from t1;
|
||||
drop table t1;
|
||||
|
||||
create table t1 (a bigint);
|
||||
insert into t1 values (1), (2), (3), (0), (0);
|
||||
alter table t1 modify a bigint not null auto_increment primary key;
|
||||
select * from t1;
|
||||
drop table t1;
|
||||
|
||||
# We still should be able to preserve zero in NO_AUTO_VALUE_ON_ZERO mode
|
||||
create table t1 (a bigint);
|
||||
insert into t1 values (0), (1), (2), (3);
|
||||
set sql_mode=NO_AUTO_VALUE_ON_ZERO;
|
||||
alter table t1 modify a bigint not null auto_increment primary key;
|
||||
set sql_mode= '';
|
||||
select * from t1;
|
||||
drop table t1;
|
||||
|
||||
# It also sensible to preserve zeroes if we are converting auto_increment
|
||||
# column to auto_increment column (or not touching it at all, which is more
|
||||
# common case probably)
|
||||
create table t1 (a int auto_increment primary key , b int null);
|
||||
set sql_mode=NO_AUTO_VALUE_ON_ZERO;
|
||||
insert into t1 values (0,1),(1,2),(2,3);
|
||||
select * from t1;
|
||||
set sql_mode= '';
|
||||
alter table t1 modify b varchar(255);
|
||||
insert into t1 values (0,4);
|
||||
select * from t1;
|
||||
drop table t1;
|
||||
|
||||
@@ -266,12 +266,12 @@ select * from t1;
|
||||
drop table t1;
|
||||
|
||||
#
|
||||
# Test for bug #4491, TIMESTAMP(19) should be possible to create and not
|
||||
# only read in 4.0
|
||||
# Let us test behavior of ALTER TABLE when it converts columns
|
||||
# containing NULL to TIMESTAMP columns.
|
||||
#
|
||||
create table t1 (ts timestamp(19));
|
||||
show create table t1;
|
||||
set TIMESTAMP=1000000000;
|
||||
insert into t1 values ();
|
||||
create table t1 (a bigint, b bigint);
|
||||
insert into t1 values (NULL, NULL), (20030101000000, 20030102000000);
|
||||
set timestamp=1000000019;
|
||||
alter table t1 modify a timestamp, modify b timestamp;
|
||||
select * from t1;
|
||||
drop table t1;
|
||||
|
||||
Reference in New Issue
Block a user