refactor IsLocalReferenceTableJoin & its usages and rename it

improve-drop-trigger2
Onur Tirtir 2020-03-03 15:07:39 +03:00
parent 653295e512
commit 5baea1dfcb
2 changed files with 12 additions and 29 deletions

View File

@ -70,7 +70,7 @@ int ExecutorLevel = 0;
/* local function forward declarations */ /* local function forward declarations */
static Relation StubRelation(TupleDesc tupleDescriptor); static Relation StubRelation(TupleDesc tupleDescriptor);
static bool AlterTableConstraintCheck(QueryDesc *queryDesc); static bool AlterTableConstraintCheck(QueryDesc *queryDesc);
static bool IsLocalReferenceTableJoinPlan(PlannedStmt *plan); static bool IsValidLocalReferenceTableJoinPlan(PlannedStmt *plan);
static List * FindCitusCustomScanStates(PlanState *planState); static List * FindCitusCustomScanStates(PlanState *planState);
static bool CitusCustomScanStateWalker(PlanState *planState, static bool CitusCustomScanStateWalker(PlanState *planState,
List **citusCustomScanStates); List **citusCustomScanStates);
@ -149,7 +149,7 @@ CitusExecutorRun(QueryDesc *queryDesc,
if (CitusHasBeenLoaded()) if (CitusHasBeenLoaded())
{ {
if (IsLocalReferenceTableJoinPlan(queryDesc->plannedstmt) && if (IsValidLocalReferenceTableJoinPlan(queryDesc->plannedstmt) &&
IsMultiStatementTransaction()) IsMultiStatementTransaction())
{ {
/* /*
@ -742,13 +742,13 @@ AlterTableConstraintCheck(QueryDesc *queryDesc)
/* /*
* IsLocalReferenceTableJoinPlan returns true if the given plan joins local tables * IsValidLocalReferenceTableJoinPlan returns true if the given plan joins local tables
* with reference table shards. * with reference table shards.
* *
* This should be consistent with IsLocalReferenceTableJoin() in distributed_planner.c. * This should be consistent with IsLocalReferenceTableJoin() in distributed_planner.c.
*/ */
static bool static bool
IsLocalReferenceTableJoinPlan(PlannedStmt *plan) IsValidLocalReferenceTableJoinPlan(PlannedStmt *plan)
{ {
bool hasReferenceTable = false; bool hasReferenceTable = false;
bool hasLocalTable = false; bool hasLocalTable = false;

View File

@ -122,7 +122,7 @@ static void PopPlannerRestrictionContext(void);
static void ResetPlannerRestrictionContext( static void ResetPlannerRestrictionContext(
PlannerRestrictionContext *plannerRestrictionContext); PlannerRestrictionContext *plannerRestrictionContext);
static bool HasUnresolvedExternParamsWalker(Node *expression, ParamListInfo boundParams); static bool HasUnresolvedExternParamsWalker(Node *expression, ParamListInfo boundParams);
static bool IsLocalReferenceTableJoin(Query *parse, List *rangeTableList); static bool IsValidLocalReferenceTableJoin(Query *parse, List *rangeTableList);
static bool QueryIsNotSimpleSelect(Node *node); static bool QueryIsNotSimpleSelect(Node *node);
static bool UpdateReferenceTablesWithShard(Node *node, void *context); static bool UpdateReferenceTablesWithShard(Node *node, void *context);
static PlannedStmt * PlanFastPathDistributedStmt(DistributedPlanningContext *planContext, static PlannedStmt * PlanFastPathDistributedStmt(DistributedPlanningContext *planContext,
@ -158,7 +158,7 @@ distributed_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
} }
else if (CitusHasBeenLoaded()) else if (CitusHasBeenLoaded())
{ {
if (IsLocalReferenceTableJoin(parse, rangeTableList)) if (IsValidLocalReferenceTableJoin(parse, rangeTableList))
{ {
/* /*
* For joins between reference tables and local tables, we replace * For joins between reference tables and local tables, we replace
@ -2341,38 +2341,21 @@ HasUnresolvedExternParamsWalker(Node *expression, ParamListInfo boundParams)
/* /*
* IsLocalReferenceTableJoin returns if the given query is a join between * IsValidLocalReferenceTableJoin returns true if the given query
* reference tables and local tables. * is a valid join query between reference tables and local tables
*/ */
static bool static bool
IsLocalReferenceTableJoin(Query *parse, List *rangeTableList) IsValidLocalReferenceTableJoin(Query *parse, List *rangeTableList)
{ {
bool hasReferenceTable = false; bool hasReferenceTable = false;
bool hasLocalTable = false; bool hasLocalTable = false;
ListCell *rangeTableCell = false; ListCell *rangeTableCell = false;
bool hasReferenceTableReplica = false;
/* /*
* We only allow join between reference tables and local tables in the * Check if we are in the coordinator and coordinator can have reference
* coordinator. * table placements
*/ */
if (!IsCoordinator()) if (!CanUseCoordinatorLocalTablesWithReferenceTables())
{
return false;
}
/*
* All groups that have pg_dist_node entries, also have reference
* table replicas.
*/
PrimaryNodeForGroup(COORDINATOR_GROUP_ID, &hasReferenceTableReplica);
/*
* If reference table doesn't have replicas on the coordinator, we don't
* allow joins with local tables.
*/
if (!hasReferenceTableReplica)
{ {
return false; return false;
} }