[demo] Do not call lock_rec_convert_impl_to_expl if a table S-lock is… - #5526
[demo] Do not call lock_rec_convert_impl_to_expl if a table S-lock is…#5526mariadb-YuchenPei wants to merge 1 commit into
Conversation
… held In lock_clust_rec_read_check_and_lock there's a test on lock_table_has(trx, index->table, LOCK_X) which if fails would result in a call to lock_rec_convert_impl_to_expl<true>, which 1. has a comment "If an implicit x-lock exists on a record, convert it to an explicit one." that does not apply if a table S-lock is held and 2. does a few things such as looking up the trx_id of the record and find the trx in a global hash trx_sys. In this patch we do the same check for a table S-lock. This could potentially improve the performance of LOCK IN SHARE MODE (TODO: check)
|
|
|
claude: I'll review PR 5526. Let me fetch the PR and its diff. I've reviewed the PR (draft/demo, single line added to The change if (lock_table_has(trx, index->table, LOCK_X)
+ || lock_table_has(trx, index->table, LOCK_S)
|| heap_no == PAGE_HEAP_NO_SUPREMUM) {
} else if (lock_rec_convert_impl_to_expl<true>(...) == trx
&& gap_mode == LOCK_REC_NOT_GAP) {Correctness — I believe it's sound, and here's the justification worth putting in the codeThe safety of skipping No — and it's a clean argument from the table-lock compatibility matrix:
So there is nothing for Strong supporting precedent: the sibling function One behavioral note: your form is slightly broader than the sec path. The sec path keys on if (lock_table_has(trx, index->table, LOCK_X)
|| lock_table_has(trx, index->table, mode) // mirrors lock_sec_rec_read_check_and_lock
|| heap_no == PAGE_HEAP_NO_SUPREMUM) {For Performance — the win is real but conditional, and the benchmark has to target the right caseThis is exactly the caveat from the earlier analysis, and it directly affects your "TODO: check":
So to actually demonstrate the win, benchmark Minor: for Things to verify / nits
Net: as a demo the reasoning is correct and it has direct precedent in the secondary-index path; the open item is proving the perf benefit on a benchmark that hits the |
… held
In lock_clust_rec_read_check_and_lock there's a test on lock_table_has(trx, index->table, LOCK_X) which if fails would result in a call to lock_rec_convert_impl_to_expl, which 1. has a comment "If an implicit x-lock exists on a record, convert it to an explicit one." that does not apply if a table S-lock is held and 2. does a few things such as looking up the trx_id of the record and find the trx in a global hash trx_sys. In this patch we do the same check for a table S-lock. This could potentially improve the performance of LOCK IN SHARE MODE (TODO: check)