MDEV-37152: Remove many calls to _current_thd()

mtr_t::trx: New public const data member. If it is nullptr,
per-connection statistics will not be updated. The transaction is
not necessarily in active state. We may merely use it as an "anchor"
for buffering updates of buf_pool.stat.n_page_gets in
trx_t::pages_accessed.

As part of this, we try to create mtr_t less often, reusing one object
in multiple places. Some read operations will
invoke mtr_t::rollback_to_savepoint() to release their own page latches
within a larger mini-transactions.

Reviewed by: Vladislav Lesin
Tested by: Saahil Alam
This commit is contained in:
Marko Mäkelä 2025-09-29 14:35:02 +03:00
commit 4369a382a1
73 changed files with 909 additions and 954 deletions

View file

@ -1298,13 +1298,11 @@ bool dict_table_t::deserialise_columns(const byte* metadata, ulint len)
}
/** Check if record in clustered index is historical row.
@param[in,out] mtr mini-transaction
@param[in] rec clustered row
@param[in] offsets offsets
@return true if row is historical */
bool
dict_index_t::vers_history_row(
const rec_t* rec,
const rec_offs* offsets)
bool dict_index_t::vers_history_row(const rec_t *rec, const rec_offs *offsets)
{
ut_ad(is_primary());
@ -1322,11 +1320,13 @@ dict_index_t::vers_history_row(
}
/** Check if record in secondary index is historical row.
@param[in,out] mtr mini-transaction
@param[in] rec record in a secondary index
@param[out] history_row true if row is historical
@return true on error */
bool
dict_index_t::vers_history_row(
mtr_t* mtr,
const rec_t* rec,
bool &history_row)
{
@ -1347,32 +1347,32 @@ dict_index_t::vers_history_row(
insert into t1 values (1, 1);
*/
bool error = false;
mem_heap_t* heap = NULL;
dict_index_t* clust_index = NULL;
rec_offs offsets_[REC_OFFS_NORMAL_SIZE];
rec_offs* offsets = offsets_;
rec_offs_init(offsets_);
mtr_t mtr;
mtr.start();
const auto sp = mtr->get_savepoint();
rec_t* clust_rec =
row_get_clust_rec(BTR_SEARCH_LEAF, rec, this, &clust_index, &mtr);
row_get_clust_rec(BTR_SEARCH_LEAF, rec, this, &clust_index, mtr);
if (clust_rec) {
mem_heap_t* heap = NULL;
offsets = rec_get_offsets(clust_rec, clust_index, offsets,
clust_index->n_core_fields,
ULINT_UNDEFINED, &heap);
history_row = clust_index->vers_history_row(clust_rec, offsets);
if (heap) {
mem_heap_free(heap);
}
} else {
ib::error() << "foreign constraints: secondary index is out of "
"sync";
ut_ad("secondary index is out of sync" == 0);
error = true;
}
mtr.commit();
if (heap) {
mem_heap_free(heap);
}
mtr->rollback_to_savepoint(sp);
return(error);
}