Skip to content

Commit 16da398

Browse files
authored
Merge pull request #8202 from FirebirdSQL/work/system-triggers
Reimplement system triggers in C++/GDML code
2 parents ec18fa5 + e9410dd commit 16da398

24 files changed

+1609
-2424
lines changed

builds/win32/msvc15/engine_static.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<ClCompile Include="..\..\..\gen\jrd\ini.cpp" />
3232
<ClCompile Include="..\..\..\gen\jrd\met.cpp" />
3333
<ClCompile Include="..\..\..\gen\jrd\scl.cpp" />
34+
<ClCompile Include="..\..\..\gen\jrd\SystemTriggers.cpp" />
3435
<ClCompile Include="..\..\..\gen\utilities\gstat\dba.cpp" />
3536
<ClCompile Include="..\..\..\src\dsql\AggNodes.cpp" />
3637
<ClCompile Include="..\..\..\src\dsql\BlrDebugWriter.cpp" />
@@ -350,6 +351,7 @@
350351
<ClInclude Include="..\..\..\src\jrd\sys-packages\SqlPackage.h" />
351352
<ClInclude Include="..\..\..\src\jrd\SysFunction.h" />
352353
<ClInclude Include="..\..\..\src\jrd\SystemPackages.h" />
354+
<ClInclude Include="..\..\..\src\jrd\SystemTriggers.h" />
353355
<ClInclude Include="..\..\..\src\jrd\TempSpace.h" />
354356
<ClInclude Include="..\..\..\src\jrd\TimeZone.h" />
355357
<ClInclude Include="..\..\..\src\jrd\tpc_proto.h" />
@@ -390,6 +392,7 @@
390392
<None Include="..\..\..\src\jrd\ini.epp" />
391393
<None Include="..\..\..\src\jrd\met.epp" />
392394
<None Include="..\..\..\src\jrd\scl.epp" />
395+
<None Include="..\..\..\src\jrd\SystemTriggers.epp" />
393396
<None Include="..\..\..\src\utilities\gstat\dba.epp" />
394397
</ItemGroup>
395398
<PropertyGroup Label="Globals">

builds/win32/msvc15/engine_static.vcxproj.filters

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@
423423
<ClCompile Include="..\..\..\gen\jrd\scl.cpp">
424424
<Filter>JRD files\GPRE cpp</Filter>
425425
</ClCompile>
426+
<ClCompile Include="..\..\..\gen\jrd\SystemTriggers.cpp">
427+
<Filter>JRD files\GPRE cpp</Filter>
428+
</ClCompile>
426429
<ClCompile Include="..\..\..\gen\jrd\dfw.cpp">
427430
<Filter>JRD files\GPRE cpp</Filter>
428431
</ClCompile>
@@ -1085,6 +1088,9 @@
10851088
<ClInclude Include="..\..\..\src\jrd\SystemPackages.h">
10861089
<Filter>Header files</Filter>
10871090
</ClInclude>
1091+
<ClInclude Include="..\..\..\src\jrd\SystemTriggers.h">
1092+
<Filter>Header files</Filter>
1093+
</ClInclude>
10881094
<ClInclude Include="..\..\..\src\jrd\Coercion.h">
10891095
<Filter>Header files</Filter>
10901096
</ClInclude>
@@ -1139,11 +1145,14 @@
11391145
<None Include="..\..\..\src\jrd\scl.epp">
11401146
<Filter>JRD files\GPRE files</Filter>
11411147
</None>
1148+
<None Include="..\..\..\src\jrd\SystemTriggers.epp">
1149+
<Filter>JRD files\GPRE files</Filter>
1150+
</None>
11421151
<None Include="..\..\..\src\utilities\gstat\dba.epp">
11431152
<Filter>Services</Filter>
11441153
</None>
11451154
<None Include="..\..\..\src\dsql\parse.y">
11461155
<Filter>DSQL</Filter>
11471156
</None>
11481157
</ItemGroup>
1149-
</Project>
1158+
</Project>

builds/win32/preprocess.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ goto :EOF
6565
@for %%i in (alice_meta) do @call :PREPROCESS alice %%i
6666
@for %%i in (metd, DdlNodes, PackageNodes) do @call :PREPROCESS dsql %%i -gds_cxx
6767
@for %%i in (gpre_meta) do @call :PREPROCESS gpre/std %%i
68-
@for %%i in (dfw, dpm, dyn_util, fun, grant, ini, met, scl, Function) do @call :PREPROCESS jrd %%i -gds_cxx
68+
@for %%i in (dfw, dpm, dyn_util, fun, grant, ini, met, scl, Function, SystemTriggers) do @call :PREPROCESS jrd %%i -gds_cxx
6969
@for %%i in (stats) do @call :PREPROCESS utilities %%i
7070
@goto :EOF
7171

@@ -78,7 +78,7 @@ goto :EOF
7878
@for %%i in (metd) do @call :PREPROCESS dsql %%i -gds_cxx
7979
@for %%i in (DdlNodes, PackageNodes) do @call :PREPROCESS dsql %%i -gds_cxx
8080
@for %%i in (gpre_meta) do @call :PREPROCESS gpre/std %%i
81-
@for %%i in (dfw, dpm, dyn_util, fun, grant, ini, met, scl, Function) do @call :PREPROCESS jrd %%i -gds_cxx
81+
@for %%i in (dfw, dpm, dyn_util, fun, grant, ini, met, scl, Function, SystemTriggers) do @call :PREPROCESS jrd %%i -gds_cxx
8282
@for %%i in (extract, isql, show) do @call :PREPROCESS isql %%i -ocxx
8383
@for %%i in (dba) do @call :PREPROCESS utilities/gstat %%i
8484
@for %%i in (stats) do @call :PREPROCESS utilities %%i

src/dsql/StmtNodes.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2781,7 +2781,7 @@ const StmtNode* EraseNode::erase(thread_db* tdbb, Request* request, WhichTrigger
27812781
spPreTriggers.release();
27822782

27832783
// Handle post operation trigger.
2784-
if (relation->rel_post_erase && whichTrig != PRE_TRIG)
2784+
if ((relation->rel_post_erase || relation->isSystem()) && whichTrig != PRE_TRIG)
27852785
{
27862786
EXE_execute_triggers(tdbb, &relation->rel_post_erase, rpb, NULL, TRIGGER_DELETE, POST_TRIG);
27872787
}
@@ -7848,7 +7848,7 @@ const StmtNode* ModifyNode::modify(thread_db* tdbb, Request* request, WhichTrigg
78487848
newRpb->rpb_number = orgRpb->rpb_number;
78497849
newRpb->rpb_number.setValid(true);
78507850

7851-
if (relation->rel_post_modify && whichTrig != PRE_TRIG)
7851+
if ((relation->rel_post_modify || relation->isSystem()) && whichTrig != PRE_TRIG)
78527852
{
78537853
EXE_execute_triggers(tdbb, &relation->rel_post_modify, orgRpb, newRpb,
78547854
TRIGGER_UPDATE, POST_TRIG);
@@ -8871,7 +8871,7 @@ const StmtNode* StoreNode::store(thread_db* tdbb, Request* request, WhichTrigger
88718871
{
88728872
SavepointChangeMarker scMarker(transaction);
88738873

8874-
if (relation && relation->rel_pre_store && whichTrig != POST_TRIG)
8874+
if (relation && (relation->rel_pre_store || relation->isSystem()) && whichTrig != POST_TRIG)
88758875
{
88768876
EXE_execute_triggers(tdbb, &relation->rel_pre_store, NULL, rpb,
88778877
TRIGGER_INSERT, PRE_TRIG);
@@ -8904,7 +8904,8 @@ const StmtNode* StoreNode::store(thread_db* tdbb, Request* request, WhichTrigger
89048904

89058905
rpb->rpb_number.setValid(true);
89068906

8907-
if (relation && relation->rel_post_store && whichTrig != PRE_TRIG)
8907+
if (relation && (relation->rel_post_store || relation->isSystem()) &&
8908+
relation->rel_post_store && whichTrig != PRE_TRIG)
89088909
{
89098910
EXE_execute_triggers(tdbb, &relation->rel_post_store, NULL, rpb,
89108911
TRIGGER_INSERT, POST_TRIG);
@@ -11660,9 +11661,10 @@ static void preModifyEraseTriggers(thread_db* tdbb, TrigVector** trigs,
1166011661
FB_NEW_POOL(*tdbb->getTransaction()->tra_pool) traRpbList(*tdbb->getTransaction()->tra_pool);
1166111662
}
1166211663

11664+
const auto relation = rpb->rpb_relation;
1166311665
const int rpblevel = tdbb->getTransaction()->tra_rpblist->PushRpb(rpb);
1166411666

11665-
if (*trigs && whichTrig != StmtNode::POST_TRIG)
11667+
if ((*trigs || relation->isSystem()) && whichTrig != StmtNode::POST_TRIG)
1166611668
{
1166711669
try
1166811670
{

src/jrd/Attachment.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ Jrd::Attachment::Attachment(MemoryPool* pool, Database* dbb, JProvider* provider
265265
att_generators(*pool),
266266
att_internal(*pool),
267267
att_dyn_req(*pool),
268+
att_internal_cached_statements(*pool),
268269
att_dec_status(DecimalStatus::DEFAULT),
269270
att_charsets(*pool),
270271
att_charset_ids(*pool),
@@ -681,9 +682,15 @@ Request* Jrd::Attachment::findSystemRequest(thread_db* tdbb, USHORT id, USHORT w
681682

682683
//Database::CheckoutLockGuard guard(this, dbb_cmp_clone_mutex);
683684

684-
fb_assert(which == IRQ_REQUESTS || which == DYN_REQUESTS);
685+
fb_assert(which == IRQ_REQUESTS || which == DYN_REQUESTS || which == CACHED_REQUESTS);
685686

686-
Statement* statement = (which == IRQ_REQUESTS ? att_internal[id] : att_dyn_req[id]);
687+
if (which == CACHED_REQUESTS && id >= att_internal_cached_statements.getCount())
688+
att_internal_cached_statements.grow(id + 1);
689+
690+
Statement* statement =
691+
which == IRQ_REQUESTS ? att_internal[id] :
692+
which == DYN_REQUESTS ? att_dyn_req[id] :
693+
att_internal_cached_statements[id];
687694

688695
if (!statement)
689696
return NULL;

src/jrd/Attachment.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ class Attachment : public pool_alloc<type_att>
666666

667667
Firebird::Array<Statement*> att_internal; // internal statements
668668
Firebird::Array<Statement*> att_dyn_req; // internal dyn statements
669+
Firebird::Array<Statement*> att_internal_cached_statements; // internal cached statements
669670
Firebird::ICryptKeyCallback* att_crypt_callback; // callback for DB crypt
670671
Firebird::DecimalStatus att_dec_status; // error handling and rounding
671672

src/jrd/RecordSourceNodes.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,6 @@ RelationSourceNode* RelationSourceNode::parse(thread_db* tdbb, CompilerScratch*
626626
{
627627
MET_scan_relation(tdbb, node->relation);
628628
}
629-
else if (node->relation->rel_flags & REL_sys_triggers)
630-
MET_parse_sys_trigger(tdbb, node->relation);
631629

632630
// generate a stream for the relation reference, assuming it is a real reference
633631

src/jrd/Relation.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,9 @@ const ULONG REL_deleted = 0x0004; // Relation known gonzo
393393
const ULONG REL_get_dependencies = 0x0008; // New relation needs dependencies during scan
394394
const ULONG REL_check_existence = 0x0010; // Existence lock released pending drop of relation
395395
const ULONG REL_blocking = 0x0020; // Blocking someone from dropping relation
396-
const ULONG REL_sys_triggers = 0x0040; // The relation has system triggers to compile
397396
const ULONG REL_sql_relation = 0x0080; // Relation defined as sql table
398397
const ULONG REL_check_partners = 0x0100; // Rescan primary dependencies and foreign references
399398
const ULONG REL_being_scanned = 0x0200; // relation scan in progress
400-
const ULONG REL_sys_trigs_being_loaded = 0x0400; // System triggers being loaded
401399
const ULONG REL_deleting = 0x0800; // relation delete in progress
402400
const ULONG REL_temp_tran = 0x1000; // relation is a GTT delete rows
403401
const ULONG REL_temp_conn = 0x2000; // relation is a GTT preserve rows

0 commit comments

Comments
 (0)