1 /*-------------------------------------------------------------------------
2  *
3  * multi_router_planner.h
4  *
5  * Declarations for public functions and types related to router planning.
6  *
7  * Copyright (c) Citus Data, Inc.
8  *
9  *-------------------------------------------------------------------------
10  */
11 
12 #ifndef MULTI_ROUTER_PLANNER_H
13 #define MULTI_ROUTER_PLANNER_H
14 
15 #include "c.h"
16 
17 #include "distributed/errormessage.h"
18 #include "distributed/log_utils.h"
19 #include "distributed/multi_logical_planner.h"
20 #include "distributed/multi_physical_planner.h"
21 #include "distributed/distributed_planner.h"
22 #include "nodes/parsenodes.h"
23 
24 
25 /* reserved alias name for UPSERTs */
26 #define CITUS_TABLE_ALIAS "citus_table_alias"
27 
28 extern bool EnableRouterExecution;
29 extern bool EnableFastPathRouterPlanner;
30 
31 extern DistributedPlan * CreateRouterPlan(Query *originalQuery, Query *query,
32 										  PlannerRestrictionContext *
33 										  plannerRestrictionContext);
34 extern DistributedPlan * CreateModifyPlan(Query *originalQuery, Query *query,
35 										  PlannerRestrictionContext *
36 										  plannerRestrictionContext);
37 extern DeferredErrorMessage * PlanRouterQuery(Query *originalQuery,
38 											  PlannerRestrictionContext *
39 											  plannerRestrictionContext,
40 											  List **placementList, uint64 *anchorShardId,
41 											  List **relationShardList,
42 											  List **prunedShardIntervalListList,
43 											  bool replacePrunedQueryWithDummy,
44 											  bool *multiShardModifyQuery,
45 											  Const **partitionValueConst,
46 											  bool *containOnlyLocalTable);
47 extern List * RelationShardListForShardIntervalList(List *shardIntervalList,
48 													bool *shardsPresent);
49 extern List * CreateTaskPlacementListForShardIntervals(List *shardIntervalList,
50 													   bool shardsPresent,
51 													   bool generateDummyPlacement,
52 													   bool hasLocalRelation);
53 extern List * RouterInsertTaskList(Query *query, bool parametersInQueryResolved,
54 								   DeferredErrorMessage **planningError);
55 extern Const * ExtractInsertPartitionKeyValue(Query *query);
56 extern List * TargetShardIntervalsForRestrictInfo(RelationRestrictionContext *
57 												  restrictionContext,
58 												  bool *multiShardQuery,
59 												  Const **partitionValueConst);
60 extern List * PlacementsForWorkersContainingAllShards(List *shardIntervalListList);
61 extern List * IntersectPlacementList(List *lhsPlacementList, List *rhsPlacementList);
62 extern DeferredErrorMessage * ModifyQuerySupported(Query *queryTree, Query *originalQuery,
63 												   bool multiShardQuery,
64 												   PlannerRestrictionContext *
65 												   plannerRestrictionContext);
66 extern DeferredErrorMessage * ErrorIfOnConflictNotSupported(Query *queryTree);
67 extern List * ShardIntervalOpExpressions(ShardInterval *shardInterval, Index rteIndex);
68 extern RelationRestrictionContext * CopyRelationRestrictionContext(
69 	RelationRestrictionContext *oldContext);
70 
71 extern Oid ExtractFirstCitusTableId(Query *query);
72 extern RangeTblEntry * ExtractSelectRangeTableEntry(Query *query);
73 extern Oid ModifyQueryResultRelationId(Query *query);
74 extern RangeTblEntry * ExtractResultRelationRTE(Query *query);
75 extern RangeTblEntry * ExtractResultRelationRTEOrError(Query *query);
76 extern RangeTblEntry * ExtractDistributedInsertValuesRTE(Query *query);
77 extern bool IsMultiRowInsert(Query *query);
78 extern void AddPartitionKeyNotNullFilterToSelect(Query *subqery);
79 extern bool UpdateOrDeleteQuery(Query *query);
80 
81 extern uint64 GetAnchorShardId(List *relationShardList);
82 extern List * TargetShardIntervalForFastPathQuery(Query *query,
83 												  bool *isMultiShardQuery,
84 												  Const *inputDistributionKeyValue,
85 												  Const **outGoingPartitionValueConst);
86 extern void GenerateSingleShardRouterTaskList(Job *job,
87 											  List *relationShardList,
88 											  List *placementList,
89 											  uint64 shardId,
90 											  bool isLocalTableModification);
91 
92 /*
93  * FastPathPlanner is a subset of router planner, that's why we prefer to
94  * keep the external function here.
95  */extern PlannedStmt * GeneratePlaceHolderPlannedStmt(Query *parse);
96 
97 extern PlannedStmt * FastPathPlanner(Query *originalQuery, Query *parse, ParamListInfo
98 									 boundParams);
99 extern bool FastPathRouterQuery(Query *query, Node **distributionKeyValue);
100 extern bool JoinConditionIsOnFalse(List *relOptInfo);
101 
102 
103 #endif /* MULTI_ROUTER_PLANNER_H */
104