Skip to content

Commit b8c5023

Browse files
committed
Cleanup trx_sys.find() calls
Replaced some trx_sys.find() calls with trx_sys.is_registered(). The latter is more appropriate in this context as it documents the intention and may provide more optimal implementation if we ever decide to.
1 parent 3c435b8 commit b8c5023

3 files changed

Lines changed: 22 additions & 19 deletions

File tree

storage/innobase/dict/dict0load.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ dict_sys_tables_rec_read(
668668
rec, DICT_FLD__SYS_TABLES__DB_TRX_ID, &len);
669669
ut_ad(len == 6 || len == UNIV_SQL_NULL);
670670
trx_id_t id = len == 6 ? trx_read_trx_id(field) : 0;
671-
if (id && !uncommitted && trx_sys.find(nullptr, id, false)) {
671+
if (id && !uncommitted && trx_sys.is_registered_nonzero(id)) {
672672
const auto savepoint = mtr->get_savepoint();
673673
heap = mem_heap_create(1024);
674674
dict_index_t* index = UT_LIST_GET_FIRST(
@@ -1079,7 +1079,7 @@ static const char *dict_load_column_low(dict_table_t *table,
10791079
const trx_id_t trx_id = trx_read_trx_id(field);
10801080

10811081
if (trx_id && mtr && use_uncommitted < 2
1082-
&& trx_sys.find(nullptr, trx_id, false)) {
1082+
&& trx_sys.is_registered_nonzero(trx_id)) {
10831083
if (use_uncommitted) {
10841084
return dict_load_column_instant;
10851085
}
@@ -1288,7 +1288,7 @@ dict_load_virtual_low(
12881288
const trx_id_t trx_id = trx_read_trx_id(field);
12891289

12901290
if (trx_id && column && !uncommitted
1291-
&& trx_sys.find(nullptr, trx_id, false)) {
1291+
&& trx_sys.is_registered_nonzero(trx_id)) {
12921292
if (!rec_get_deleted_flag(rec, 0)) {
12931293
return dict_load_virtual_none;
12941294
}
@@ -1639,7 +1639,7 @@ dict_load_field_low(
16391639
if (!trx_id) {
16401640
ut_ad(!rec_get_deleted_flag(rec, 0));
16411641
} else if (!mtr || uncommitted) {
1642-
} else if (trx_sys.find(nullptr, trx_id, false)) {
1642+
} else if (trx_sys.is_registered_nonzero(trx_id)) {
16431643
const auto savepoint = mtr->get_savepoint();
16441644
dict_index_t* sys_field = UT_LIST_GET_FIRST(
16451645
dict_sys.sys_fields->indexes);
@@ -1856,7 +1856,7 @@ dict_load_index_low(
18561856
if (!trx_id) {
18571857
ut_ad(!rec_get_deleted_flag(rec, 0));
18581858
} else if (!mtr || uncommitted) {
1859-
} else if (trx_sys.find(nullptr, trx_id, false)) {
1859+
} else if (trx_sys.is_registered_nonzero(trx_id)) {
18601860
const auto savepoint = mtr->get_savepoint();
18611861
dict_index_t* sys_index = UT_LIST_GET_FIRST(
18621862
dict_sys.sys_indexes->indexes);
@@ -2744,7 +2744,7 @@ static dberr_t dict_load_foreign_cols(dict_foreign_t *foreign, trx_id_t trx_id)
27442744

27452745
const trx_id_t id = trx_read_trx_id(field);
27462746
if (!id) {
2747-
} else if (id != trx_id && trx_sys.find(nullptr, id, false)) {
2747+
} else if (id != trx_id && trx_sys.is_registered_nonzero(id)) {
27482748
const auto savepoint = mtr.get_savepoint();
27492749
rec_offs* offsets = rec_get_offsets(
27502750
rec, sys_index, nullptr, true, ULINT_UNDEFINED,
@@ -2934,7 +2934,7 @@ dict_load_foreign(
29342934
const trx_id_t tid = trx_read_trx_id(field);
29352935

29362936
if (tid && tid != trx_id && !uncommitted
2937-
&& trx_sys.find(nullptr, tid, false)) {
2937+
&& trx_sys.is_registered_nonzero(tid)) {
29382938
const auto savepoint = mtr.get_savepoint();
29392939
rec_offs* offsets = rec_get_offsets(
29402940
rec, sys_index, nullptr, true, ULINT_UNDEFINED, &heap);

storage/innobase/dict/dict0stats.cc

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ dict_stats_update_transient_for_index(
11661166
}
11671167

11681168
const auto bulk_trx_id = index->table->bulk_trx_id;
1169-
if (bulk_trx_id && trx_sys.find(nullptr, bulk_trx_id, false)) {
1169+
if (trx_sys.is_registered(nullptr, bulk_trx_id)) {
11701170
err= DB_SUCCESS_LOCKED_REC;
11711171
goto invalid;
11721172
}
@@ -1231,11 +1231,9 @@ dberr_t dict_stats_update_transient(dict_table_t *table) noexcept
12311231
return DB_SUCCESS;
12321232
}
12331233

1234-
if (trx_id_t bulk_trx_id = table->bulk_trx_id) {
1235-
if (trx_sys.find(nullptr, bulk_trx_id, false)) {
1236-
dict_stats_empty_table(table, false);
1237-
return DB_SUCCESS_LOCKED_REC;
1238-
}
1234+
if (trx_sys.is_registered(nullptr, table->bulk_trx_id)) {
1235+
dict_stats_empty_table(table, false);
1236+
return DB_SUCCESS_LOCKED_REC;
12391237
}
12401238

12411239
for (; index != NULL; index = dict_table_get_next_index(index)) {
@@ -2365,7 +2363,7 @@ static index_stats_t dict_stats_analyze_index(dict_index_t* index)
23652363
result.n_leaf_pages = size ? size : 1;
23662364

23672365
const auto bulk_trx_id = index->table->bulk_trx_id;
2368-
if (bulk_trx_id && trx_sys.find(nullptr, bulk_trx_id, false)) {
2366+
if (trx_sys.is_registered(nullptr, bulk_trx_id)) {
23692367
result.set_bulk_operation();
23702368
goto empty_index;
23712369
}
@@ -2634,11 +2632,9 @@ dberr_t dict_stats_update_persistent(dict_table_t *table) noexcept
26342632

26352633
DEBUG_SYNC_C("dict_stats_update_persistent");
26362634

2637-
if (trx_id_t bulk_trx_id = table->bulk_trx_id) {
2638-
if (trx_sys.find(nullptr, bulk_trx_id, false)) {
2639-
dict_stats_empty_table(table, false);
2640-
return DB_SUCCESS_LOCKED_REC;
2641-
}
2635+
if (trx_sys.is_registered(nullptr, table->bulk_trx_id)) {
2636+
dict_stats_empty_table(table, false);
2637+
return DB_SUCCESS_LOCKED_REC;
26422638
}
26432639

26442640
/* analyze the clustered index first */

storage/innobase/include/trx0sys.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,13 @@ class trx_sys_t
11641164
}
11651165

11661166

1167+
bool is_registered_nonzero(trx_id_t id, trx_t *caller_trx= nullptr)
1168+
{
1169+
ut_ad(id);
1170+
return find(caller_trx, id, false);
1171+
}
1172+
1173+
11671174
bool is_registered(trx_t *caller_trx, trx_id_t id)
11681175
{
11691176
return id && find(caller_trx, id, false);

0 commit comments

Comments
 (0)