Skip to content

Commit

Permalink
MDEV-7254: Assigned expression is evaluated twice when updating
Browse files Browse the repository at this point in the history
column TIMESTAMP NOT NULL
      
Analysis: Problem was that value->is_null() function is called
even when user had explicitly set the value for timestamp
field. Calling this function had the side effect that
expression was evaluated twice.
      
Fix: (by Sergei Golubchik) check instead value->null_value.
  • Loading branch information
Jan Lindström committed Jan 16, 2015
1 parent 813af4c commit 6164157
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
44 changes: 44 additions & 0 deletions mysql-test/r/type_timestamp.result
Original file line number Diff line number Diff line change
Expand Up @@ -645,3 +645,47 @@ MAX(dt) = '2011-01-06 12:34:30'
1
DROP TABLE t1;
End of 5.5 tests
#
# MDEV-7254: Assigned expression is evaluated twice when updating column TIMESTAMP NOT NULL
#
create table t1(value timestamp not null);
set @a:=0;
create function f1 () returns timestamp
begin
set @a = @a + 1;
return NULL;
end//
set timestamp=12340;
insert t1 values (f1());
select @a, value from t1;
@a value
1 1970-01-01 05:25:40
set timestamp=12350;
update t1 set value = f1();
select @a, value from t1;
@a value
2 1970-01-01 05:25:50
drop table t1;
drop function f1;
set timestamp=0;
create table t1(value timestamp null);
set @a:=0;
create function f1 () returns timestamp
begin
set @a = @a + 1;
return NULL;
end//
set timestamp=12340;
insert t1 values (f1());
select @a, value from t1;
@a value
1 NULL
set timestamp=12350;
update t1 set value = f1();
select @a, value from t1;
@a value
2 NULL
drop table t1;
drop function f1;
set timestamp=0;
End of 10.0 tests
45 changes: 45 additions & 0 deletions mysql-test/t/type_timestamp.test
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,48 @@ SELECT MAX(dt) = '2011-01-06 12:34:30' FROM t1;
DROP TABLE t1;

--echo End of 5.5 tests

--echo #
--echo # MDEV-7254: Assigned expression is evaluated twice when updating column TIMESTAMP NOT NULL
--echo #

create table t1(value timestamp not null);
set @a:=0;
delimiter //;
create function f1 () returns timestamp
begin
set @a = @a + 1;
return NULL;
end//
delimiter ;//
set timestamp=12340;
insert t1 values (f1());
select @a, value from t1;
set timestamp=12350;
update t1 set value = f1();
select @a, value from t1;
drop table t1;
drop function f1;
set timestamp=0;

# Verify no regressions to TIMESTAMP NULL
create table t1(value timestamp null);
set @a:=0;
delimiter //;
create function f1 () returns timestamp
begin
set @a = @a + 1;
return NULL;
end//
delimiter ;//
set timestamp=12340;
insert t1 values (f1());
select @a, value from t1;
set timestamp=12350;
update t1 set value = f1();
select @a, value from t1;
drop table t1;
drop function f1;
set timestamp=0;

--echo End of 10.0 tests
2 changes: 1 addition & 1 deletion sql/field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4899,7 +4899,7 @@ void Field_timestamp::set_explicit_default(Item *value)
{
if (((value->type() == Item::DEFAULT_VALUE_ITEM &&
!((Item_default_value*)value)->arg) ||
(!maybe_null() && value->is_null())))
(!maybe_null() && value->null_value)))
return;
set_has_explicit_value();
}
Expand Down

0 comments on commit 6164157

Please sign in to comment.