Skip to content

Commit aaf0e33

Browse files
committed
Correction: revert code related with WITH CHECK OPTION internal triggers.
1 parent 31780d5 commit aaf0e33

File tree

7 files changed

+44
-15
lines changed

7 files changed

+44
-15
lines changed

src/dsql/StmtNodes.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11550,8 +11550,11 @@ static RelationSourceNode* pass1Update(thread_db* tdbb, CompilerScratch* csb, jr
1155011550

1155111551
for (FB_SIZE_T i = 0; i < trigger->getCount(); i++)
1155211552
{
11553-
userTriggers = true;
11554-
break;
11553+
if (!(*trigger)[i].sysTrigger)
11554+
{
11555+
userTriggers = true;
11556+
break;
11557+
}
1155511558
}
1155611559

1155711560
if (userTriggers)

src/jrd/Monitoring.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,8 @@ void Monitoring::dumpAttachment(thread_db* tdbb, Attachment* attachment, ULONG g
14981498
{
14991499
request->adjustCallerStats();
15001500

1501-
if (!(request->getStatement()->flags & Statement::FLAG_INTERNAL) &&
1501+
if (!(request->getStatement()->flags &
1502+
(Statement::FLAG_INTERNAL | Statement::FLAG_SYS_TRIGGER)) &&
15021503
request->req_caller)
15031504
{
15041505
putCall(record, request);
@@ -1512,7 +1513,7 @@ void Monitoring::dumpAttachment(thread_db* tdbb, Attachment* attachment, ULONG g
15121513

15131514
for (const auto statement : attachment->att_statements)
15141515
{
1515-
if (!(statement->flags & Statement::FLAG_INTERNAL))
1516+
if (!(statement->flags & (Statement::FLAG_INTERNAL | Statement::FLAG_SYS_TRIGGER)))
15161517
{
15171518
const string plan = Optimizer::getPlan(tdbb, statement, true);
15181519
putStatement(record, statement, plan);
@@ -1526,7 +1527,7 @@ void Monitoring::dumpAttachment(thread_db* tdbb, Attachment* attachment, ULONG g
15261527
{
15271528
const auto statement = request->getStatement();
15281529

1529-
if (!(statement->flags & Statement::FLAG_INTERNAL))
1530+
if (!(statement->flags & (Statement::FLAG_INTERNAL | Statement::FLAG_SYS_TRIGGER)))
15301531
{
15311532
const string plan = Optimizer::getPlan(tdbb, statement, true);
15321533
putRequest(record, request, plan);

src/jrd/Statement.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ class PlanEntry;
3434
class Statement : public pool_alloc<type_req>
3535
{
3636
public:
37+
static const unsigned FLAG_SYS_TRIGGER = 0x01;
3738
static const unsigned FLAG_INTERNAL = 0x02;
3839
static const unsigned FLAG_IGNORE_PERM = 0x04;
3940
//static const unsigned FLAG_VERSION4 = 0x08;
40-
static const unsigned FLAG_POWERFUL = FLAG_INTERNAL | FLAG_IGNORE_PERM;
41+
static const unsigned FLAG_POWERFUL = FLAG_SYS_TRIGGER | FLAG_INTERNAL | FLAG_IGNORE_PERM;
4142

4243
//static const unsigned MAP_LENGTH; // CVC: Moved to dsql/Nodes.h as STREAM_MAP_LENGTH
4344
static const unsigned MAX_CLONES = 1000;

src/jrd/jrd.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,9 @@ void Trigger::compile(thread_db* tdbb)
944944
if (ssDefiner.asBool())
945945
statement->triggerInvoker = att->getUserId(owner);
946946

947+
if (sysTrigger)
948+
statement->flags |= Statement::FLAG_SYS_TRIGGER | Statement::FLAG_INTERNAL;
949+
947950
if (flags & TRG_ignore_perm)
948951
statement->flags |= Statement::FLAG_IGNORE_PERM;
949952
}
@@ -9221,7 +9224,11 @@ ISC_STATUS thread_db::getCancelState(ISC_STATUS* secondary)
92219224
if ((attachment->att_flags & ATT_cancel_raise) &&
92229225
!(attachment->att_flags & ATT_cancel_disable))
92239226
{
9224-
if ((!transaction || !(transaction->tra_flags & TRA_system)))
9227+
if ((!request ||
9228+
!(request->getStatement()->flags &
9229+
// temporary change to fix shutdown
9230+
(/*Statement::FLAG_INTERNAL | */Statement::FLAG_SYS_TRIGGER))) &&
9231+
(!transaction || !(transaction->tra_flags & TRA_system)))
92259232
{
92269233
return isc_cancelled;
92279234
}

src/jrd/jrd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class Trigger
142142
Firebird::HalfStaticArray<UCHAR, 128> debugInfo; // Debug info
143143
Statement* statement = nullptr; // Compiled statement
144144
bool releaseInProgress = false;
145+
bool sysTrigger = false;
145146
FB_UINT64 type = 0; // Trigger type
146147
USHORT flags = 0; // Flags as they are in RDB$TRIGGERS table
147148
jrd_rel* relation = nullptr; // Trigger parent relation

src/jrd/met.epp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static int blocking_ast_relation(void*);
115115
static int partners_ast_relation(void*);
116116
static int rescan_ast_relation(void*);
117117
static ULONG get_rel_flags_from_FLAGS(USHORT);
118-
static void get_trigger(thread_db*, jrd_rel*, bid*, bid*, TrigVector**, const TEXT*, FB_UINT64,
118+
static void get_trigger(thread_db*, jrd_rel*, bid*, bid*, TrigVector**, const TEXT*, FB_UINT64, bool,
119119
USHORT, const MetaName&, const string&, const bid*, TriState ssDefiner);
120120
static bool get_type(thread_db*, USHORT*, const UCHAR*, const TEXT*);
121121
static void lookup_view_contexts(thread_db*, jrd_rel*);
@@ -124,7 +124,7 @@ static ValueExprNode* parse_field_default_blr(thread_db* tdbb, bid* blob_id);
124124
static BoolExprNode* parse_field_validation_blr(thread_db* tdbb, bid* blob_id, const MetaName name);
125125
static bool resolve_charset_and_collation(thread_db*, USHORT*, const UCHAR*, const UCHAR*);
126126
static void save_trigger_data(thread_db*, TrigVector**, jrd_rel*, Statement*, blb*, blb*,
127-
const TEXT*, FB_UINT64, USHORT, const MetaName&, const string&,
127+
const TEXT*, FB_UINT64, bool, USHORT, const MetaName&, const string&,
128128
const bid*, TriState ssDefiner);
129129
static void scan_partners(thread_db*, jrd_rel*);
130130
static bool verify_TRG_ignore_perm(thread_db*, const MetaName&);
@@ -2003,6 +2003,7 @@ void MET_load_trigger(thread_db* tdbb,
20032003
triggers,
20042004
TRG.RDB$TRIGGER_NAME,
20052005
TRG.RDB$TRIGGER_TYPE,
2006+
(bool) TRG.RDB$SYSTEM_FLAG,
20062007
trig_flags,
20072008
engine,
20082009
entryPoint,
@@ -2023,6 +2024,7 @@ void MET_load_trigger(thread_db* tdbb,
20232024
triggers + trigger_action,
20242025
TRG.RDB$TRIGGER_NAME,
20252026
(UCHAR) trigger_action,
2027+
(bool) TRG.RDB$SYSTEM_FLAG,
20262028
trig_flags,
20272029
engine,
20282030
entryPoint,
@@ -4545,7 +4547,7 @@ ULONG MET_get_rel_flags_from_TYPE(USHORT type)
45454547
static void get_trigger(thread_db* tdbb, jrd_rel* relation,
45464548
bid* blob_id, bid* debug_blob_id, TrigVector** ptr,
45474549
const TEXT* name, FB_UINT64 type,
4548-
USHORT flags,
4550+
bool sys_trigger, USHORT flags,
45494551
const MetaName& engine, const string& entryPoint,
45504552
const bid* body, TriState ssDefiner)
45514553
{
@@ -4575,7 +4577,7 @@ static void get_trigger(thread_db* tdbb, jrd_rel* relation,
45754577
debugInfoBlob = blb::open(tdbb, attachment->getSysTransaction(), debug_blob_id);
45764578

45774579
save_trigger_data(tdbb, ptr, relation, NULL, blrBlob, debugInfoBlob,
4578-
name, type, flags, engine, entryPoint, body, ssDefiner);
4580+
name, type, sys_trigger, flags, engine, entryPoint, body, ssDefiner);
45794581
}
45804582

45814583

@@ -4927,7 +4929,7 @@ static bool resolve_charset_and_collation(thread_db* tdbb,
49274929
static void save_trigger_data(thread_db* tdbb, TrigVector** ptr, jrd_rel* relation,
49284930
Statement* statement, blb* blrBlob, blb* debugInfoBlob,
49294931
const TEXT* name, FB_UINT64 type,
4930-
USHORT flags,
4932+
bool sys_trigger, USHORT flags,
49314933
const MetaName& engine, const string& entryPoint,
49324934
const bid* body, TriState ssDefiner)
49334935
{
@@ -4984,6 +4986,7 @@ static void save_trigger_data(thread_db* tdbb, TrigVector** ptr, jrd_rel* relati
49844986

49854987
t.type = type;
49864988
t.flags = flags;
4989+
t.sysTrigger = sys_trigger;
49874990
t.statement = statement;
49884991
t.relation = relation;
49894992
t.engine = engine;
@@ -5179,7 +5182,18 @@ void MET_store_dependencies(thread_db* tdbb,
51795182

51805183
SET_TDBB(tdbb);
51815184

5182-
const bool checkTableScope = dependency_type == obj_computed;
5185+
const Trigger* t = nullptr;
5186+
const bool checkTableScope =
5187+
(dependency_type == obj_computed) ||
5188+
(dependency_type == obj_trigger) && (dep_rel != 0) &&
5189+
(
5190+
(t = findTrigger(dep_rel->rel_pre_erase, object_name)) ||
5191+
(t = findTrigger(dep_rel->rel_pre_modify, object_name)) ||
5192+
(t = findTrigger(dep_rel->rel_pre_store, object_name)) ||
5193+
(t = findTrigger(dep_rel->rel_post_erase, object_name)) ||
5194+
(t = findTrigger(dep_rel->rel_post_modify, object_name)) ||
5195+
(t = findTrigger(dep_rel->rel_post_store, object_name))
5196+
) && t && (t->sysTrigger);
51835197

51845198
while (dependencies.hasData())
51855199
{

src/jrd/trace/TraceJrdHelpers.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ class TraceTrigCompile
431431
const auto attachment = m_tdbb->getAttachment();
432432
const auto trace_mgr = attachment->att_trace_manager;
433433

434-
m_need_trace = trace_mgr->needs(ITraceFactory::TRACE_EVENT_TRIGGER_COMPILE);
434+
m_need_trace = !trigger->sysTrigger &&
435+
trace_mgr->needs(ITraceFactory::TRACE_EVENT_TRIGGER_COMPILE);
435436

436437
if (!m_need_trace)
437438
return;
@@ -528,7 +529,8 @@ class TraceTrigExecute
528529
const auto transaction = m_tdbb->getTransaction();
529530
const auto trace_mgr = attachment->att_trace_manager;
530531

531-
m_need_trace = trace_mgr->needs(ITraceFactory::TRACE_EVENT_TRIGGER_EXECUTE);
532+
m_need_trace = !(m_request->getStatement()->flags & Statement::FLAG_SYS_TRIGGER) &&
533+
trace_mgr->needs(ITraceFactory::TRACE_EVENT_TRIGGER_EXECUTE);
532534

533535
if (!m_need_trace)
534536
return;

0 commit comments

Comments
 (0)