8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 22:43:03 +01:00

Avoid not necessary allocations from pool when performing FK check.

It fixes most significant source of contention in SuperServer when FK index is created by many parallel workers, as discussed in #8071
This commit is contained in:
Vlad Khorsun 2024-07-05 23:11:42 +03:00 committed by Dmitry Yemanov
parent eb90a372ef
commit 695d8f4203

View File

@ -1681,7 +1681,9 @@ static idx_e check_duplicates(thread_db* tdbb,
index_desc* insertion_idx = insertion->iib_descriptor;
record_param rpb;
rpb.rpb_relation = insertion->iib_relation;
rpb.rpb_record = NULL;
AutoTempRecord gc_record(VIO_gc_record(tdbb, rpb.rpb_relation));
rpb.rpb_record = gc_record;
jrd_rel* const relation_1 = insertion->iib_relation;
RecordBitmap::Accessor accessor(insertion->iib_duplicates);
@ -1754,7 +1756,8 @@ static idx_e check_duplicates(thread_db* tdbb,
}
} while (accessor.getNext());
delete rpb.rpb_record;
if (rpb.rpb_record != gc_record)
delete rpb.rpb_record;
return result;
}
@ -1952,12 +1955,13 @@ static idx_e check_partner_index(thread_db* tdbb,
if ((idx->idx_flags & idx_descending) != (partner_idx.idx_flags & idx_descending))
BTR_complement_key(key);
RecordBitmap* bitmap = NULL;
RecordBitmap bm(*tdbb->getDefaultPool());
RecordBitmap* bitmap = &bm;
BTR_evaluate(tdbb, &retrieval, &bitmap, NULL);
// if there is a bitmap, it means duplicates were found
if (bitmap)
if (bitmap->getFirst())
{
index_insertion insertion;
insertion.iib_descriptor = &partner_idx;
@ -1972,7 +1976,6 @@ static idx_e check_partner_index(thread_db* tdbb,
result = result ? idx_e_foreign_references_present : idx_e_ok;
if (idx->idx_flags & idx_foreign)
result = result ? idx_e_ok : idx_e_foreign_target_doesnt_exist;
delete bitmap;
}
else if (idx->idx_flags & idx_foreign)
result = idx_e_foreign_target_doesnt_exist;