mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-20403 Assertion 0' or Assertion
btr_validate_index(index, 0)' failed in row_upd_sec_index_entry or error code 126: Index is corrupted upon UPDATE with TIMESTAMP..ON UPDATE
remove a special treatment of a bare DEFAULT keyword that made it
behave inconsistently and differently from DEFAULT(column).
Now all forms of the explicit assignment of a default column value
behave identically, and all count as an explicitly assigned value
(for the purpose of ON UPDATE NOW).
followup for c7c481f4d9
This commit is contained in:
@ -3372,7 +3372,7 @@ insert into t1 values (b, 5, '5 the value of the DEFAULT(a), that is b');
|
||||
select * from t1 order by t;
|
||||
a b t
|
||||
5 5 1 column is omitted
|
||||
5 5 2 column gets DEFAULT, keyword
|
||||
4 5 2 column gets DEFAULT, keyword
|
||||
4 5 3 column gets DEFAULT(a), expression
|
||||
4 5 4 also expression DEFAULT(0)+0
|
||||
4 5 5 the value of the DEFAULT(a), that is b
|
||||
|
@ -3116,3 +3116,32 @@ select if(@new = j, 'correct', 'wrong') from t1;
|
||||
if(@new = j, 'correct', 'wrong')
|
||||
correct
|
||||
drop table t1;
|
||||
create table t1 (a int, b varchar(20) default 'foo');
|
||||
insert t1 values (1,'bla'),(2, 'bar');
|
||||
select * from t1;
|
||||
a b
|
||||
1 bla
|
||||
2 bar
|
||||
update t1 set b=default where a=1;
|
||||
select * from t1;
|
||||
a b
|
||||
1 foo
|
||||
2 bar
|
||||
drop table t1;
|
||||
create table t1 (
|
||||
a int,
|
||||
b timestamp default '2010-10-10 10:10:10' on update now(),
|
||||
c varchar(100) default 'x');
|
||||
insert t1 (a) values (1),(2);
|
||||
select * from t1;
|
||||
a b c
|
||||
1 2010-10-10 10:10:10 x
|
||||
2 2010-10-10 10:10:10 x
|
||||
set timestamp=unix_timestamp('2011-11-11 11-11-11');
|
||||
update t1 set b=default, c=default(b) where a=1;
|
||||
select * from t1;
|
||||
a b c
|
||||
1 2010-10-10 10:10:10 2010-10-10 10:10:10
|
||||
2 2010-10-10 10:10:10 x
|
||||
drop table t1;
|
||||
set timestamp=default;
|
||||
|
@ -24,14 +24,14 @@ source 'include/function_defaults.inc';
|
||||
# MDEV-20403 Assertion `0' or Assertion `btr_validate_index(index, 0)' failed in row_upd_sec_index_entry or error code 126: Index is corrupted upon UPDATE with TIMESTAMP..ON UPDATE
|
||||
#
|
||||
|
||||
# ON UPDATE DEFAULT NOW and indexed virtual columns
|
||||
# ON UPDATE NOW and indexed virtual columns
|
||||
create table t1 (t timestamp, i int, v timestamp as (t) virtual, key(v));
|
||||
insert t1 (t,i) values ('2006-03-01 23:59:59',1);
|
||||
update t1 set i = 2;
|
||||
check table t1;
|
||||
drop table t1;
|
||||
|
||||
# ON UPDATE DEFAULT NOW and triggers
|
||||
# ON UPDATE NOW and triggers
|
||||
create table t1 (t timestamp, i int);
|
||||
create trigger tr1 before update on t1 for each row set @new:=new.t;
|
||||
insert t1 (t,i) values ('2006-03-01 23:59:59', 1);
|
||||
@ -46,3 +46,24 @@ insert t1 (i) values (1);
|
||||
update t1, t1 as t2 set t1.i = 2;
|
||||
select if(@new = j, 'correct', 'wrong') from t1;
|
||||
drop table t1;
|
||||
|
||||
# SET xxx=DEFAULT
|
||||
create table t1 (a int, b varchar(20) default 'foo');
|
||||
insert t1 values (1,'bla'),(2, 'bar');
|
||||
select * from t1;
|
||||
update t1 set b=default where a=1;
|
||||
select * from t1;
|
||||
drop table t1;
|
||||
|
||||
# ON UPDATE NOW and SET xxx=DEFAULT
|
||||
create table t1 (
|
||||
a int,
|
||||
b timestamp default '2010-10-10 10:10:10' on update now(),
|
||||
c varchar(100) default 'x');
|
||||
insert t1 (a) values (1),(2);
|
||||
select * from t1;
|
||||
set timestamp=unix_timestamp('2011-11-11 11-11-11');
|
||||
update t1 set b=default, c=default(b) where a=1;
|
||||
select * from t1;
|
||||
drop table t1;
|
||||
set timestamp=default;
|
||||
|
27
sql/field.cc
27
sql/field.cc
@ -11106,33 +11106,6 @@ key_map Field::get_possible_keys()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Mark the field as having an explicit default value.
|
||||
|
||||
@param value if available, the value that the field is being set to
|
||||
|
||||
@note
|
||||
Fields that have an explicit default value should not be updated
|
||||
automatically via the DEFAULT or ON UPDATE functions. The functions
|
||||
that deal with data change functionality (INSERT/UPDATE/LOAD),
|
||||
determine if there is an explicit value for each field before performing
|
||||
the data change, and call this method to mark the field.
|
||||
|
||||
If the 'value' parameter is NULL, then the field is marked unconditionally
|
||||
as having an explicit value. If 'value' is not NULL, then it can be further
|
||||
analyzed to check if it really should count as a value.
|
||||
*/
|
||||
|
||||
bool Field::set_explicit_default(Item *value)
|
||||
{
|
||||
if (value->type() == Item::DEFAULT_VALUE_ITEM &&
|
||||
!((Item_default_value*)value)->arg)
|
||||
return false;
|
||||
set_has_explicit_value();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Field::validate_value_in_record_with_warn(THD *thd, const uchar *record)
|
||||
{
|
||||
my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->read_set);
|
||||
|
@ -990,7 +990,6 @@ public:
|
||||
{
|
||||
return bitmap_is_set(&table->has_value_set, field_index);
|
||||
}
|
||||
bool set_explicit_default(Item *value);
|
||||
|
||||
virtual bool binary() const { return 1; }
|
||||
virtual bool zero_pack() const { return 1; }
|
||||
|
@ -9010,8 +9010,6 @@ int Item_default_value::save_in_field(Field *field_arg, bool no_conversions)
|
||||
return Item_field::save_in_field(field_arg, no_conversions);
|
||||
}
|
||||
|
||||
if (field_arg->default_value && field_arg->default_value->flags)
|
||||
return 0; // defaut fields will be set later, no need to do it twice
|
||||
return field_arg->save_in_field_default_value(context->error_processor ==
|
||||
&view_error_processor);
|
||||
}
|
||||
@ -9263,7 +9261,7 @@ bool Item_trigger_field::set_value(THD *thd, sp_rcontext * /*ctx*/, Item **it)
|
||||
int err_code= item->save_in_field(field, 0);
|
||||
|
||||
field->table->copy_blobs= copy_blobs_saved;
|
||||
field->set_explicit_default(item);
|
||||
field->set_has_explicit_value();
|
||||
|
||||
return err_code < 0;
|
||||
}
|
||||
|
@ -8068,7 +8068,7 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
|
||||
my_message(ER_UNKNOWN_ERROR, ER_THD(thd, ER_UNKNOWN_ERROR), MYF(0));
|
||||
goto err;
|
||||
}
|
||||
rfield->set_explicit_default(value);
|
||||
rfield->set_has_explicit_value();
|
||||
}
|
||||
|
||||
if (update)
|
||||
@ -8265,7 +8265,6 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values,
|
||||
{
|
||||
List_iterator_fast<Item> v(values);
|
||||
List<TABLE> tbl_list;
|
||||
bool all_fields_have_values= true;
|
||||
Item *value;
|
||||
Field *field;
|
||||
bool abort_on_warning_saved= thd->abort_on_warning;
|
||||
@ -8318,11 +8317,8 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values,
|
||||
else
|
||||
if (value->save_in_field(field, 0) < 0)
|
||||
goto err;
|
||||
all_fields_have_values &= field->set_explicit_default(value);
|
||||
field->set_has_explicit_value();
|
||||
}
|
||||
if (!all_fields_have_values && table->default_field &&
|
||||
table->update_default_fields(ignore_errors))
|
||||
goto err;
|
||||
/* Update virtual fields */
|
||||
thd->abort_on_warning= FALSE;
|
||||
if (table->vfield &&
|
||||
|
Reference in New Issue
Block a user