diff --git a/src/dsql/StmtNodes.cpp b/src/dsql/StmtNodes.cpp index 7e23a403f6..d722242311 100644 --- a/src/dsql/StmtNodes.cpp +++ b/src/dsql/StmtNodes.cpp @@ -11550,8 +11550,11 @@ static RelationSourceNode* pass1Update(thread_db* tdbb, CompilerScratch* csb, jr for (FB_SIZE_T i = 0; i < trigger->getCount(); i++) { - userTriggers = true; - break; + if (!(*trigger)[i].sysTrigger) + { + userTriggers = true; + break; + } } if (userTriggers) diff --git a/src/jrd/Monitoring.cpp b/src/jrd/Monitoring.cpp index 07fc189db2..4fef7456dc 100644 --- a/src/jrd/Monitoring.cpp +++ b/src/jrd/Monitoring.cpp @@ -1498,7 +1498,8 @@ void Monitoring::dumpAttachment(thread_db* tdbb, Attachment* attachment, ULONG g { request->adjustCallerStats(); - if (!(request->getStatement()->flags & Statement::FLAG_INTERNAL) && + if (!(request->getStatement()->flags & + (Statement::FLAG_INTERNAL | Statement::FLAG_SYS_TRIGGER)) && request->req_caller) { putCall(record, request); @@ -1512,7 +1513,7 @@ void Monitoring::dumpAttachment(thread_db* tdbb, Attachment* attachment, ULONG g for (const auto statement : attachment->att_statements) { - if (!(statement->flags & Statement::FLAG_INTERNAL)) + if (!(statement->flags & (Statement::FLAG_INTERNAL | Statement::FLAG_SYS_TRIGGER))) { const string plan = Optimizer::getPlan(tdbb, statement, true); putStatement(record, statement, plan); @@ -1526,7 +1527,7 @@ void Monitoring::dumpAttachment(thread_db* tdbb, Attachment* attachment, ULONG g { const auto statement = request->getStatement(); - if (!(statement->flags & Statement::FLAG_INTERNAL)) + if (!(statement->flags & (Statement::FLAG_INTERNAL | Statement::FLAG_SYS_TRIGGER))) { const string plan = Optimizer::getPlan(tdbb, statement, true); putRequest(record, request, plan); diff --git a/src/jrd/Statement.h b/src/jrd/Statement.h index 8db158bee8..da27d6ff88 100644 --- a/src/jrd/Statement.h +++ b/src/jrd/Statement.h @@ -34,10 +34,11 @@ class PlanEntry; class Statement : public pool_alloc { public: + static const unsigned FLAG_SYS_TRIGGER = 0x01; static const unsigned FLAG_INTERNAL = 0x02; static const unsigned FLAG_IGNORE_PERM = 0x04; //static const unsigned FLAG_VERSION4 = 0x08; - static const unsigned FLAG_POWERFUL = FLAG_INTERNAL | FLAG_IGNORE_PERM; + static const unsigned FLAG_POWERFUL = FLAG_SYS_TRIGGER | FLAG_INTERNAL | FLAG_IGNORE_PERM; //static const unsigned MAP_LENGTH; // CVC: Moved to dsql/Nodes.h as STREAM_MAP_LENGTH static const unsigned MAX_CLONES = 1000; diff --git a/src/jrd/jrd.cpp b/src/jrd/jrd.cpp index 13c931aec9..08f560ddf7 100644 --- a/src/jrd/jrd.cpp +++ b/src/jrd/jrd.cpp @@ -944,6 +944,9 @@ void Trigger::compile(thread_db* tdbb) if (ssDefiner.asBool()) statement->triggerInvoker = att->getUserId(owner); + if (sysTrigger) + statement->flags |= Statement::FLAG_SYS_TRIGGER | Statement::FLAG_INTERNAL; + if (flags & TRG_ignore_perm) statement->flags |= Statement::FLAG_IGNORE_PERM; } @@ -9221,7 +9224,11 @@ ISC_STATUS thread_db::getCancelState(ISC_STATUS* secondary) if ((attachment->att_flags & ATT_cancel_raise) && !(attachment->att_flags & ATT_cancel_disable)) { - if ((!transaction || !(transaction->tra_flags & TRA_system))) + if ((!request || + !(request->getStatement()->flags & + // temporary change to fix shutdown + (/*Statement::FLAG_INTERNAL | */Statement::FLAG_SYS_TRIGGER))) && + (!transaction || !(transaction->tra_flags & TRA_system))) { return isc_cancelled; } diff --git a/src/jrd/jrd.h b/src/jrd/jrd.h index 677aafba7f..9bb03c60e8 100644 --- a/src/jrd/jrd.h +++ b/src/jrd/jrd.h @@ -142,6 +142,7 @@ public: Firebird::HalfStaticArray debugInfo; // Debug info Statement* statement = nullptr; // Compiled statement bool releaseInProgress = false; + bool sysTrigger = false; FB_UINT64 type = 0; // Trigger type USHORT flags = 0; // Flags as they are in RDB$TRIGGERS table jrd_rel* relation = nullptr; // Trigger parent relation diff --git a/src/jrd/met.epp b/src/jrd/met.epp index 48e8cc406d..f16f2190f4 100644 --- a/src/jrd/met.epp +++ b/src/jrd/met.epp @@ -115,7 +115,7 @@ static int blocking_ast_relation(void*); static int partners_ast_relation(void*); static int rescan_ast_relation(void*); static ULONG get_rel_flags_from_FLAGS(USHORT); -static void get_trigger(thread_db*, jrd_rel*, bid*, bid*, TrigVector**, const TEXT*, FB_UINT64, +static void get_trigger(thread_db*, jrd_rel*, bid*, bid*, TrigVector**, const TEXT*, FB_UINT64, bool, USHORT, const MetaName&, const string&, const bid*, TriState ssDefiner); static bool get_type(thread_db*, USHORT*, const UCHAR*, const TEXT*); 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); static BoolExprNode* parse_field_validation_blr(thread_db* tdbb, bid* blob_id, const MetaName name); static bool resolve_charset_and_collation(thread_db*, USHORT*, const UCHAR*, const UCHAR*); static void save_trigger_data(thread_db*, TrigVector**, jrd_rel*, Statement*, blb*, blb*, - const TEXT*, FB_UINT64, USHORT, const MetaName&, const string&, + const TEXT*, FB_UINT64, bool, USHORT, const MetaName&, const string&, const bid*, TriState ssDefiner); static void scan_partners(thread_db*, jrd_rel*); static bool verify_TRG_ignore_perm(thread_db*, const MetaName&); @@ -2003,6 +2003,7 @@ void MET_load_trigger(thread_db* tdbb, triggers, TRG.RDB$TRIGGER_NAME, TRG.RDB$TRIGGER_TYPE, + (bool) TRG.RDB$SYSTEM_FLAG, trig_flags, engine, entryPoint, @@ -2023,6 +2024,7 @@ void MET_load_trigger(thread_db* tdbb, triggers + trigger_action, TRG.RDB$TRIGGER_NAME, (UCHAR) trigger_action, + (bool) TRG.RDB$SYSTEM_FLAG, trig_flags, engine, entryPoint, @@ -4545,7 +4547,7 @@ ULONG MET_get_rel_flags_from_TYPE(USHORT type) static void get_trigger(thread_db* tdbb, jrd_rel* relation, bid* blob_id, bid* debug_blob_id, TrigVector** ptr, const TEXT* name, FB_UINT64 type, - USHORT flags, + bool sys_trigger, USHORT flags, const MetaName& engine, const string& entryPoint, const bid* body, TriState ssDefiner) { @@ -4575,7 +4577,7 @@ static void get_trigger(thread_db* tdbb, jrd_rel* relation, debugInfoBlob = blb::open(tdbb, attachment->getSysTransaction(), debug_blob_id); save_trigger_data(tdbb, ptr, relation, NULL, blrBlob, debugInfoBlob, - name, type, flags, engine, entryPoint, body, ssDefiner); + name, type, sys_trigger, flags, engine, entryPoint, body, ssDefiner); } @@ -4927,7 +4929,7 @@ static bool resolve_charset_and_collation(thread_db* tdbb, static void save_trigger_data(thread_db* tdbb, TrigVector** ptr, jrd_rel* relation, Statement* statement, blb* blrBlob, blb* debugInfoBlob, const TEXT* name, FB_UINT64 type, - USHORT flags, + bool sys_trigger, USHORT flags, const MetaName& engine, const string& entryPoint, const bid* body, TriState ssDefiner) { @@ -4984,6 +4986,7 @@ static void save_trigger_data(thread_db* tdbb, TrigVector** ptr, jrd_rel* relati t.type = type; t.flags = flags; + t.sysTrigger = sys_trigger; t.statement = statement; t.relation = relation; t.engine = engine; @@ -5179,7 +5182,18 @@ void MET_store_dependencies(thread_db* tdbb, SET_TDBB(tdbb); - const bool checkTableScope = dependency_type == obj_computed; + const Trigger* t = nullptr; + const bool checkTableScope = + (dependency_type == obj_computed) || + (dependency_type == obj_trigger) && (dep_rel != 0) && + ( + (t = findTrigger(dep_rel->rel_pre_erase, object_name)) || + (t = findTrigger(dep_rel->rel_pre_modify, object_name)) || + (t = findTrigger(dep_rel->rel_pre_store, object_name)) || + (t = findTrigger(dep_rel->rel_post_erase, object_name)) || + (t = findTrigger(dep_rel->rel_post_modify, object_name)) || + (t = findTrigger(dep_rel->rel_post_store, object_name)) + ) && t && (t->sysTrigger); while (dependencies.hasData()) { diff --git a/src/jrd/trace/TraceJrdHelpers.h b/src/jrd/trace/TraceJrdHelpers.h index 7458d7f078..3a4614c462 100644 --- a/src/jrd/trace/TraceJrdHelpers.h +++ b/src/jrd/trace/TraceJrdHelpers.h @@ -431,7 +431,8 @@ public: const auto attachment = m_tdbb->getAttachment(); const auto trace_mgr = attachment->att_trace_manager; - m_need_trace = trace_mgr->needs(ITraceFactory::TRACE_EVENT_TRIGGER_COMPILE); + m_need_trace = !trigger->sysTrigger && + trace_mgr->needs(ITraceFactory::TRACE_EVENT_TRIGGER_COMPILE); if (!m_need_trace) return; @@ -528,7 +529,8 @@ public: const auto transaction = m_tdbb->getTransaction(); const auto trace_mgr = attachment->att_trace_manager; - m_need_trace = trace_mgr->needs(ITraceFactory::TRACE_EVENT_TRIGGER_EXECUTE); + m_need_trace = !(m_request->getStatement()->flags & Statement::FLAG_SYS_TRIGGER) && + trace_mgr->needs(ITraceFactory::TRACE_EVENT_TRIGGER_EXECUTE); if (!m_need_trace) return;