• Marko Mäkelä's avatar
    MDEV-16675 Unnecessary explicit lock acquisition during UPDATE or DELETE · 1748a31a
    Marko Mäkelä authored
    In InnoDB, an INSERT will not create an explicit lock object. Instead,
    the inserted record is initially implicitly locked by the transaction
    that wrote its trx_t::id to the hidden system column DB_TRX_ID.
    (Other transactions would check if DB_TRX_ID is referring to a
    transaction that has not been committed.)
    
    If a record was inserted in the current transaction, it would be
    implicitly locked by that transaction. Only if some other transaction
    is requesting access to the record, the implicit lock should be
    converted to an explicit one, so that the waits-for graph can be
    constructed for detecting deadlocks and lock wait timeouts.
    
    Before this fix, InnoDB would convert implicit locks to
    explicit ones, even if no conflict exists.
    
    lock_rec_convert_impl_to_expl(): Return whether caller_trx
    already holds an explicit lock that covers the record.
    
    row_vers_impl_x_locked_low(): Avoid a lookup if the record matches
    caller_trx->id.
    
    lock_trx_has_expl_x_lock(): Renamed from lock_trx_has_rec_x_lock().
    
    row_upd_clust_step(): In a debug assertion, check for implicit lock
    before invoking lock_trx_has_expl_x_lock().
    
    rw_trx_hash_t::find(): Make do_ref_count a mandatory parameter.
    Assert that trx_id is not 0 (the caller should check it).
    
    trx_sys_t::is_registered(): Only invoke find() if id != 0.
    
    trx_sys_t::find(): Add the optional parameter do_ref_count.
    
    lock_rec_queue_validate(): Avoid lookup for trx_id == 0.
    1748a31a
trx0trx.cc 59.4 KB