an3l / my_playground

My playground with python, nginx, docker and server!
0 stars 0 forks source link

MDEV-19761 Before Trigger not processed for Not Null Columns #9

Open an3l opened 5 years ago

an3l commented 5 years ago

Description

The field rate is not marked as NULL and it is marked as not having a value in the VALUES() list, so when the trigger does new.rate=if(new.rate is null,5,new.rate) the field doesn't get 5, it gets its old value (basically garbage), so the result is incorrect. record1_field and record0_field When another trigger doesif new.rate is null then set new.rate = 5; end if, the field gets no value at all, and because it was not listed in VALUES, the server returns an error "field without DEFAULT and without value"

We need to see why the field is not marked as NULL? The trigger is not wrong, the field not being NULL is wrong, so no need to look into how triggers work.

Links

[MDEV-19761] [S.G. patch MDEV-8605]

an3l commented 5 years ago

Debug

mysql_insert():1006
(gdb) p **f
+p **f
$35 = {
  <Value_source> = {<No data fields>}, 
  members of Field: 
  _vptr.Field = 0x555556a91810 <vtable for Field_long+16>, 
  ptr = 0x7fffe0023069 "\001", 
  null_ptr = 0x7fffe0023068 "\375\001", 
  table = 0x7fffe0021cb0, 
  orig_table = 0x7fffe0021cb0, 
  table_name = 0x7fffe0021d98, 
  field_name = 0x7fffe00257e1 "id", 
  option_list = 0x0, 
  option_struct = 0x0, 
  comment = {
    str = 0x5555563c02b9 "", 
    length = 0
  }, 
  key_start = {
    map = 0
  }, 
  part_of_key = {
    map = 0
  }, 
  part_of_key_not_clustered = {
    map = 0
  }, 
  part_of_sortkey = {
    map = 0
  }, 
  unireg_check = Field::NONE, 
  field_length = 11, 
  flags = 134217728, 
  field_index = 0, 
  null_bit = 2 '\002', 
  is_created_from_null_item = false, 
  is_stat_field = false, 
  cond_selectivity = 1, 
  next_equal_field = 0x0, 
  read_stats = 0x0, 
  collected_stats = 0x0, 
  vcol_info = 0x0, 
  stored_in_db = true
}

bt:

#0  Item_field::switch_to_nullable_fields_processor (this=0x7fffe0007000, arg=0x7fffe001b1b0 "\240\060\002\340\377\177") at sql/item.cc:2
445
#1  0x000055555597b568 in Item::walk (this=0x7fffe0007000, processor=&virtual table offset 936, walk_subquery=true, arg=0x7fffe001b1b0 "\
240\060\002\340\377\177") at sql/item.h:1426
#2  0x00005555559d3783 in switch_to_nullable_trigger_fields (items=..., table=0x7fffe0021cb0) at sql/sql_base.cc:8955
#3  0x0000555555a0c646 in mysql_insert (thd=0x5555578aa7f0, table_list=0x7fffe0006a00, fields=..., values_list=..., update_fields=..., up
date_values=..., duplic=DUP_ERROR, ignore=false) at sql/sql_insert.cc:911
#4  0x0000555555a30a95 in mysql_execute_command (thd=0x5555578aa7f0) at sql/sql_parse.cc:3667
#5  0x0000555555a3bc4b in mysql_parse (thd=0x5555578aa7f0, rawbuf=0x7fffe0006918 "insert into t1 (id) values (1)", length=30, parser_stat
e=0x7ffff09fb210) at sql/sql_parse.cc:7209
2    bool Item_field::switch_to_nullable_fields_processor(uchar *arg)                                                            │
   │2443    {                                                                                                                           │
B+ │2444      Field **new_fields= (Field **)arg;                                                                                        │
  >│2445      set_field_to_new_field(&field, new_fields);                                                                               │
   │2446      set_field_to_new_field(&result_field, new_fields);                                                                        │
   │2447      maybe_null= field && field->maybe_null();                                                                                 │
   │2448      return 0;                                                                                                                 │
   │2449    }

0686c34d22a5 set_new_field

0 Field::maybe_null (this=0x7fffe00230a0) at sql/field.h:1047