-
Notifications
You must be signed in to change notification settings - Fork 642
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename triggers on the shard re-create the trigger on shell table
- Loading branch information
1 parent
455850d
commit 8eb5401
Showing
7 changed files
with
217 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/*------------------------------------------------------------------------- | ||
* trigger.c | ||
* | ||
* This file contains functions to create and process triggers objects on | ||
* citus tables. | ||
* | ||
* Copyright (c) Citus Data, Inc. | ||
* | ||
*------------------------------------------------------------------------- | ||
*/ | ||
#include "postgres.h" | ||
#include "distributed/pg_version_constants.h" | ||
|
||
#include "distributed/citus_ruleutils.h" | ||
#include "distributed/commands.h" | ||
#include "access/genam.h" | ||
#if PG_VERSION_NUM >= PG_VERSION_12 | ||
#include "access/table.h" | ||
#else | ||
#include "access/heapam.h" | ||
#include "access/htup_details.h" | ||
#endif | ||
#include "catalog/indexing.h" | ||
#include "catalog/namespace.h" | ||
#include "catalog/pg_trigger.h" | ||
#include "utils/fmgroids.h" | ||
|
||
/* | ||
* GetTableTriggerCommands returns the list of DDL commands to (re)create | ||
* triggers for the given table. | ||
*/ | ||
List * | ||
GetTableTriggerCommands(Oid relationOid) | ||
{ | ||
List *triggerDDLEventList = NIL; | ||
ScanKeyData scanKey[1]; | ||
int scanKeyCount = 1; | ||
|
||
/* | ||
* Set search_path to NIL so that all objects outside of pg_catalog will be | ||
* schema-prefixed. pg_catalog will be added automatically when we call | ||
* PushOverrideSearchPath(), since we set addCatalog to true; | ||
*/ | ||
OverrideSearchPath *overridePath = GetOverrideSearchPath(CurrentMemoryContext); | ||
overridePath->schemas = NIL; | ||
overridePath->addCatalog = true; | ||
PushOverrideSearchPath(overridePath); | ||
|
||
bool useIndex = true; | ||
|
||
Relation pgTrigger = heap_open(TriggerRelationId, AccessShareLock); | ||
|
||
ScanKeyInit(&scanKey[0], Anum_pg_trigger_tgrelid, | ||
BTEqualStrategyNumber, F_OIDEQ, relationOid); | ||
|
||
SysScanDesc scanDescriptor = systable_beginscan(pgTrigger, TriggerRelidNameIndexId, | ||
useIndex, NULL, scanKeyCount, | ||
scanKey); | ||
|
||
HeapTuple heapTuple = systable_getnext(scanDescriptor); | ||
while (HeapTupleIsValid(heapTuple)) | ||
{ | ||
Oid triggerId = get_relation_trigger_oid_compat(heapTuple); | ||
char *statementDef = pg_get_triggerdef_command(triggerId); | ||
|
||
triggerDDLEventList = lappend(triggerDDLEventList, statementDef); | ||
|
||
heapTuple = systable_getnext(scanDescriptor); | ||
} | ||
|
||
systable_endscan(scanDescriptor); | ||
heap_close(pgTrigger, NoLock); | ||
|
||
/* revert back to original search_path */ | ||
PopOverrideSearchPath(); | ||
|
||
return triggerDDLEventList; | ||
} | ||
|
||
|
||
/* | ||
* get_relation_trigger_oid_compat returns OID of the trigger represented | ||
* by the constraintForm, which is passed as an heapTuple. OID of the | ||
* trigger is already stored in the triggerForm struct if major PostgreSQL | ||
* version is 12. However, in the older versions, we should utilize | ||
* HeapTupleGetOid to deduce that OID with no cost. | ||
*/ | ||
Oid | ||
get_relation_trigger_oid_compat(HeapTuple heapTuple) | ||
{ | ||
Assert(heapTuple != NULL); | ||
|
||
Oid triggerOid = InvalidOid; | ||
|
||
#if PG_VERSION_NUM >= PG_VERSION_12 | ||
Form_pg_trigger triggerForm = (Form_pg_trigger) GETSTRUCT(heapTuple); | ||
triggerOid = triggerForm->oid; | ||
#else | ||
triggerOid = HeapTupleGetOid(heapTuple); | ||
#endif | ||
|
||
return triggerOid; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters