summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavan Deolasee2015-12-15 08:17:32 +0000
committerPavan Deolasee2016-10-18 09:24:57 +0000
commit8a65b1816f19b9c86b472b128c51a9442b2c5edc (patch)
treea98a186214d6f1eb00ed60c34661944225ed344a
parent39d316ba1927f3238bde0ec24778113894ddfec7 (diff)
Add a developer GUC "enable_datanode_row_triggers" to allow ROW TRIGGERS to be
executed on the datanodes. This must be used with caution. Postgres-XL does not officially support triggers yet. One of the reasons for not supporting triggers is that a trigger function executed on a datanode may not have access to all the required data since the data may not reside on the datanode. But if users are confident that the triggers can be safely executed on the datanode, they may turn this GUC on. Still since the feature is not well tested, we don't recommend users to use this without thorough testing and knowing consequences.
-rw-r--r--src/backend/commands/trigger.c3
-rw-r--r--src/backend/tcop/utility.c29
-rw-r--r--src/backend/utils/misc/guc.c10
-rw-r--r--src/include/commands/trigger.h4
-rw-r--r--src/pl/plpgsql/src/pl_exec.c2
5 files changed, 42 insertions, 6 deletions
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index 14214de160..734b32b2b6 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -106,6 +106,9 @@ static void AfterTriggerSaveEvent(EState *estate, ResultRelInfo *relinfo,
List *recheckIndexes, Bitmapset *modifiedCols);
static void AfterTriggerEnlargeQueryState(void);
+#ifdef XCP
+bool enable_datanode_row_triggers;
+#endif
/*
* Create a trigger. Returns the address of the created trigger.
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 90a68c7e64..79d2b922be 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -2273,11 +2273,30 @@ ProcessUtilitySlow(Node *parsetree,
case T_CreateTrigStmt:
#ifdef PGXC
- /* Postgres-XC does not support yet triggers */
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("Postgres-XL does not support TRIGGER yet"),
- errdetail("The feature is not currently supported")));
+ if (!enable_datanode_row_triggers)
+ {
+ /* Postgres-XC does not support yet triggers */
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("Postgres-XL does not support TRIGGER yet"),
+ errdetail("The feature is not currently supported")));
+ }
+ else
+ {
+ if (!((CreateTrigStmt *) parsetree)->row)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("STATEMENT triggers not supported"),
+ errhint("Though enable_datanode_row_triggers "
+ "is ON, Postgres-XL only supports ROW "
+ "triggers")));
+ else
+ elog(WARNING, "Developer option "
+ "enable_datanode_row_triggers is ON. "
+ "Triggers will be executed on the datanodes "
+ "and must not require access to other nodes. "
+ "Use with caution");
+ }
if (IS_PGXC_LOCAL_COORDINATOR)
ExecUtilityStmtOnNodes(queryString, NULL, sentToRemote, false, EXEC_ON_ALL_NODES, false);
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index bf80a0ed60..a68bb994c7 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -64,6 +64,7 @@
#include "pgstat.h"
#ifdef PGXC
#include "commands/tablecmds.h"
+#include "commands/trigger.h"
#include "nodes/nodes.h"
#include "pgxc/execRemote.h"
#include "pgxc/locator.h"
@@ -976,6 +977,15 @@ static struct config_bool ConfigureNamesBool[] =
false,
NULL, NULL, NULL
},
+ {
+ {"enable_datanode_row_triggers", PGC_POSTMASTER, DEVELOPER_OPTIONS,
+ gettext_noop("Enables datanode-only ROW triggers"),
+ NULL
+ },
+ &enable_datanode_row_triggers,
+ false,
+ NULL, NULL, NULL
+ },
#endif
{
{"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
diff --git a/src/include/commands/trigger.h b/src/include/commands/trigger.h
index 72a6b4a31b..f14507d337 100644
--- a/src/include/commands/trigger.h
+++ b/src/include/commands/trigger.h
@@ -100,6 +100,10 @@ typedef struct TriggerData
#define SESSION_REPLICATION_ROLE_LOCAL 2
extern PGDLLIMPORT int SessionReplicationRole;
+#ifdef XCP
+extern bool enable_datanode_row_triggers;
+#endif
+
/*
* States at which a trigger can be fired. These are the
* possible values for pg_trigger.tgenabled.
diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c
index e803c2fe72..b117816bde 100644
--- a/src/pl/plpgsql/src/pl_exec.c
+++ b/src/pl/plpgsql/src/pl_exec.c
@@ -3478,7 +3478,7 @@ exec_stmt_execsql(PLpgSQL_execstate *estate,
/* PGXCTODO: Support a better parameter interface for XC with DMLs */
if
#ifdef XCP
- (IS_PGXC_DATANODE &&
+ (IS_PGXC_DATANODE && !enable_datanode_row_triggers &&
#endif
(q->commandType == CMD_INSERT ||
q->commandType == CMD_UPDATE ||