• Aleksey Midenkov's avatar
    MDEV-20812 Unexpected ER_ROW_IS_REFERENCED_2 upon DELETE from versioned table with FK · 7ae0be25
    Aleksey Midenkov authored
    MDEV-16210 original case was wrongly allowed versioned DELETE from
    referenced table where reference is by non-primary key. InnoDB UPDATE
    has optimization for new rows not changing its clustered index
    position. In this case InnoDB doesn't update all secondary indexes and
    misses the one holding the referenced key. The fix was to disable this
    optimization for versioned DELETE. In case of versioned DELETE we
    forcely update all secondary indexes and therefore check them for
    constraints.
    
    But the above fix raised another problem with versioned DELETE on
    foreign table side. In case when there was no corresponding record in
    referenced table (illegal foreign reference can be done with "set
    foreign_key_checks=off") there was spurious constraint check (because
    versioned DELETE is actually UPDATE) and hence the operation failed
    with constraint error.
    
    MDEV-16210 tried to fix the above problem by checking foreign table
    instead of referenced table and that at least was illegal.
    
    Constraint check is done by row_ins_check_foreign_constraint() no
    matter what kind of table is checked, referenced or foreign
    (controlled by check_ref argument).
    
    Referenced table is checked by row_upd_check_references_constraints().
    Foreign table is checked by row_ins_check_foreign_constraints().
    
    Current fix rolls back the wrong fix for the above problem and
    disables referenced table check for DELETE on foreign side by
    introducing `check_foreign` argument which when set to *false* skips
    row_ins_check_foreign_constraints() call.
    7ae0be25
row0ins.cc 102 KB