Skip to content

Commit d3c4841

Browse files
committed
Skip execution of AFTER UPDATE system ref constraints triggers if update have not changed key fields.
1 parent b5f5ba1 commit d3c4841

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/jrd/exe.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,17 @@ void EXE_execute_triggers(thread_db* tdbb,
11571157
{
11581158
for (TrigVector::iterator ptr = vector->begin(); ptr != vector->end(); ++ptr)
11591159
{
1160+
// The system trigger that implement cascading action can be skipped if
1161+
// no PK/UK field have been changed by UPDATE.
1162+
1163+
if ((which_trig == StmtNode::POST_TRIG) && (trigger_action == TRIGGER_UPDATE) &&
1164+
(ptr->sysTrigger == fb_sysflag_referential_constraint))
1165+
{
1166+
fb_assert(new_rpb);
1167+
if (!(new_rpb->rpb_runtime_flags & RPB_uk_updated))
1168+
continue;
1169+
}
1170+
11601171
if (trigger_action == TRIGGER_DDL && ddl_action)
11611172
{
11621173
// Skip triggers not matching our action

src/jrd/idx.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,8 @@ void IDX_modify(thread_db* tdbb,
12831283
RelationPages* relPages = org_rpb->rpb_relation->getPages(tdbb);
12841284
WIN window(relPages->rel_pg_space_id, -1);
12851285

1286+
new_rpb->rpb_runtime_flags &= ~RPB_uk_updated;
1287+
12861288
while (BTR_next_index(tdbb, org_rpb->rpb_relation, transaction, &idx, &window))
12871289
{
12881290
IndexErrorContext context(new_rpb->rpb_relation, &idx);
@@ -1346,6 +1348,9 @@ void IDX_modify(thread_db* tdbb,
13461348
{
13471349
context.raise(tdbb, error_code, new_rpb->rpb_record);
13481350
}
1351+
1352+
if (idx.idx_flags & (idx_primary | idx_unique))
1353+
new_rpb->rpb_runtime_flags |= RPB_uk_updated;
13491354
}
13501355
}
13511356

src/jrd/req.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ const USHORT RPB_undo_data = 0x02; // data got from undo log
136136
const USHORT RPB_undo_read = 0x04; // read was performed using the undo log
137137
const USHORT RPB_undo_deleted = 0x08; // read was performed using the undo log, primary version is deleted
138138
const USHORT RPB_just_deleted = 0x10; // record was just deleted by us
139+
const USHORT RPB_uk_updated = 0x20; // set by IDX_modify if it insert key into any primary or unique index
139140

140141
const USHORT RPB_UNDO_FLAGS = (RPB_undo_data | RPB_undo_read | RPB_undo_deleted);
141142
const USHORT RPB_CLEAR_FLAGS = (RPB_UNDO_FLAGS | RPB_just_deleted);

0 commit comments

Comments
 (0)