Skip to content

Commit 9926ab8

Browse files
committed
Reimplement system triggers in C++/GDML code.
1 parent 2c48a4e commit 9926ab8

23 files changed

+1532
-1982
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 9 additions & 10 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);
@@ -11549,11 +11550,8 @@ static RelationSourceNode* pass1Update(thread_db* tdbb, CompilerScratch* csb, jr
1154911550

1155011551
for (FB_SIZE_T i = 0; i < trigger->getCount(); i++)
1155111552
{
11552-
if (!(*trigger)[i].sysTrigger)
11553-
{
11554-
userTriggers = true;
11555-
break;
11556-
}
11553+
userTriggers = true;
11554+
break;
1155711555
}
1155811556

1155911557
if (userTriggers)
@@ -11660,9 +11658,10 @@ static void preModifyEraseTriggers(thread_db* tdbb, TrigVector** trigs,
1166011658
FB_NEW_POOL(*tdbb->getTransaction()->tra_pool) traRpbList(*tdbb->getTransaction()->tra_pool);
1166111659
}
1166211660

11661+
const auto relation = rpb->rpb_relation;
1166311662
const int rpblevel = tdbb->getTransaction()->tra_rpblist->PushRpb(rpb);
1166411663

11665-
if (*trigs && whichTrig != StmtNode::POST_TRIG)
11664+
if ((*trigs || relation->isSystem()) && whichTrig != StmtNode::POST_TRIG)
1166611665
{
1166711666
try
1166811667
{

src/jrd/Monitoring.cpp

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

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

15141513
for (const auto statement : attachment->att_statements)
15151514
{
1516-
if (!(statement->flags & (Statement::FLAG_INTERNAL | Statement::FLAG_SYS_TRIGGER)))
1515+
if (!(statement->flags & Statement::FLAG_INTERNAL))
15171516
{
15181517
const string plan = Optimizer::getPlan(tdbb, statement, true);
15191518
putStatement(record, statement, plan);
@@ -1527,7 +1526,7 @@ void Monitoring::dumpAttachment(thread_db* tdbb, Attachment* attachment, ULONG g
15271526
{
15281527
const auto statement = request->getStatement();
15291528

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

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

src/jrd/Statement.h

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

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

0 commit comments

Comments
 (0)