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

Fixed bug CORE-3925 : Creating self-referential FK crashes database (bug-check) whether constraint violation had place

This commit is contained in:
hvlad 2019-04-22 13:34:18 +03:00
parent e109b7d9a3
commit 3f794b6c9c
3 changed files with 40 additions and 3 deletions

View File

@ -3073,6 +3073,34 @@ static void cleanup_index_creation(thread_db* tdbb, DeferredWork* work, jrd_tra*
IDXN.RDB$INDEX_ID.NULL = TRUE;
END_MODIFY
}
if (!IDXN.RDB$FOREIGN_KEY.NULL)
{
index_desc idx;
idx.idx_id = idx_invalid;
idx.idx_flags = idx_foreign;
jrd_rel* partner_relation = NULL;
if (MET_lookup_partner(tdbb, relation, &idx, work->dfw_name.c_str()))
{
partner_relation = MET_lookup_relation_id(tdbb, idx.idx_primary_relation, true);
}
if (partner_relation)
{
// signal to other processes about new constraint
relation->rel_flags |= REL_check_partners;
LCK_lock(tdbb, relation->rel_partners_lock, LCK_EX, LCK_WAIT);
LCK_release(tdbb, relation->rel_partners_lock);
if (relation != partner_relation)
{
partner_relation->rel_flags |= REL_check_partners;
LCK_lock(tdbb, partner_relation->rel_partners_lock, LCK_EX, LCK_WAIT);
LCK_release(tdbb, partner_relation->rel_partners_lock);
}
}
}
}
}
END_FOR

View File

@ -153,6 +153,7 @@ void IDX_check_access(thread_db* tdbb, CompilerScratch* csb, jrd_rel* view, jrd_
if (!BTR_description(tdbb, referenced_relation, referenced_root,
&referenced_idx, index_id))
{
CCH_RELEASE(tdbb, &referenced_window);
BUGCHECK(173); // msg 173 referenced index description not found
}
@ -205,10 +206,11 @@ bool IDX_check_master_types(thread_db* tdbb, index_desc& idx, jrd_rel* partner_r
index_root_page* root = (index_root_page*) CCH_FETCH(tdbb, &window, LCK_read, pag_root);
// get the description of the partner index
if (!BTR_description(tdbb, partner_relation, root, &partner_idx, idx.idx_primary_index))
BUGCHECK(175); // msg 175 partner index description not found
const bool ok = BTR_description(tdbb, partner_relation, root, &partner_idx, idx.idx_primary_index);
CCH_RELEASE(tdbb, &window);
if (!ok)
BUGCHECK(175); // msg 175 partner index description not found
// make sure partner index have the same segment count as our
fb_assert(idx.idx_count == partner_idx.idx_count);
@ -1279,7 +1281,10 @@ static idx_e check_partner_index(thread_db* tdbb,
index_desc partner_idx;
if (!BTR_description(tdbb, partner_relation, root, &partner_idx, index_id))
{
CCH_RELEASE(tdbb, &window);
BUGCHECK(175); // msg 175 partner index description not found
}
bool starting = false;
USHORT segment;

View File

@ -4988,6 +4988,8 @@ void scan_partners(thread_db* tdbb, jrd_rel* relation)
RC.RDB$CONSTRAINT_TYPE EQ FOREIGN_KEY AND
IDX.RDB$RELATION_NAME EQ relation->rel_name.c_str() AND
IND.RDB$INDEX_NAME EQ IDX.RDB$FOREIGN_KEY AND
IDX.RDB$INDEX_ID > 0 AND
IND.RDB$INDEX_ID > 0 AND
IND.RDB$UNIQUE_FLAG = 1
{
//// ASF: Hack fix for CORE-4304, until nasty interactions between dfw and met are not resolved.
@ -5046,6 +5048,8 @@ void scan_partners(thread_db* tdbb, jrd_rel* relation)
IDX IN RDB$INDICES CROSS
IND IN RDB$INDICES WITH
IDX.RDB$UNIQUE_FLAG = 1 AND
IDX.RDB$INDEX_ID > 0 AND
IND.RDB$INDEX_ID > 0 AND
IDX.RDB$RELATION_NAME EQ relation->rel_name.c_str() AND
IND.RDB$FOREIGN_KEY EQ IDX.RDB$INDEX_NAME
{