1 /*-------------------------------------------------------------------------
2  *
3  * utility_hook.h
4  *	  Citus utility hook and related functionality.
5  *
6  * Copyright (c) Citus Data, Inc.
7  *-------------------------------------------------------------------------
8  */
9 
10 #ifndef MULTI_UTILITY_H
11 #define MULTI_UTILITY_H
12 
13 #include "distributed/pg_version_constants.h"
14 
15 #include "postgres.h"
16 
17 #include "utils/relcache.h"
18 #include "tcop/utility.h"
19 
20 #include "distributed/coordinator_protocol.h"
21 #include "distributed/version_compat.h"
22 #include "distributed/worker_transaction.h"
23 
24 typedef enum
25 {
26 	PROPSETCMD_INVALID = -1,
27 	PROPSETCMD_NONE, /* do not propagate SET commands */
28 	PROPSETCMD_LOCAL, /* propagate SET LOCAL commands */
29 	PROPSETCMD_SESSION, /* propagate SET commands, but not SET LOCAL ones */
30 	PROPSETCMD_ALL /* propagate all SET commands */
31 } PropSetCmdBehavior;
32 extern PropSetCmdBehavior PropagateSetCommands;
33 extern bool EnableDDLPropagation;
34 extern bool EnableDependencyCreation;
35 extern bool EnableCreateTypePropagation;
36 extern bool EnableAlterRolePropagation;
37 extern bool EnableAlterRoleSetPropagation;
38 extern bool EnableAlterDatabaseOwner;
39 extern int UtilityHookLevel;
40 
41 
42 /*
43  * A DDLJob encapsulates the remote tasks and commands needed to process all or
44  * part of a distributed DDL command. It hold the distributed relation's oid,
45  * the original DDL command string (for MX DDL propagation), and a task list of
46  * DDL_TASK-type Tasks to be executed.
47  */
48 typedef struct DDLJob
49 {
50 	Oid targetRelationId;      /* oid of the target distributed relation */
51 	bool concurrentIndexCmd;   /* related to a CONCURRENTLY index command? */
52 
53 	/*
54 	 * Whether to commit and start a new transaction before sending commands
55 	 * (only applies to CONCURRENTLY commands). This is needed for REINDEX CONCURRENTLY
56 	 * and CREATE INDEX CONCURRENTLY on local shards, which would otherwise
57 	 * get blocked waiting for the current transaction to finish.
58 	 */
59 	bool startNewTransaction;
60 
61 	const char *commandString; /* initial (coordinator) DDL command string */
62 	List *taskList;            /* worker DDL tasks to execute */
63 } DDLJob;
64 
65 
66 extern void multi_ProcessUtility(PlannedStmt *pstmt, const char *queryString,
67 #if PG_VERSION_NUM >= PG_VERSION_14
68 								 bool readOnlyTree,
69 #endif
70 								 ProcessUtilityContext context, ParamListInfo params,
71 								 struct QueryEnvironment *queryEnv, DestReceiver *dest,
72 								 QueryCompletionCompat *completionTag
73 								 );
74 extern void ProcessUtilityParseTree(Node *node, const char *queryString,
75 									ProcessUtilityContext context, ParamListInfo
76 									params,
77 									DestReceiver *dest,
78 									QueryCompletionCompat *completionTag
79 									);
80 extern void MarkInvalidateForeignKeyGraph(void);
81 extern void InvalidateForeignKeyGraphForDDL(void);
82 extern List * DDLTaskList(Oid relationId, const char *commandString);
83 extern List * NodeDDLTaskList(TargetWorkerSet targets, List *commands);
84 extern bool AlterTableInProgress(void);
85 extern bool DropSchemaOrDBInProgress(void);
86 extern void UndistributeDisconnectedCitusLocalTables(void);
87 extern void NotifyUtilityHookConstraintDropped(void);
88 extern void ResetConstraintDropped(void);
89 extern void ExecuteDistributedDDLJob(DDLJob *ddlJob);
90 
91 /* forward declarations for sending custom commands to a distributed table */
92 extern DDLJob * CreateCustomDDLTaskList(Oid relationId, TableDDLCommand *command);
93 
94 #endif /* MULTI_UTILITY_H */
95