implement CanUseCoordinatorLocalTablesWithReferenceTables and refactor existing usages

improve-drop-trigger2
Onur Tirtir 2020-03-03 13:38:21 +03:00
parent df95b5fe6e
commit 653295e512
3 changed files with 38 additions and 19 deletions

View File

@ -752,28 +752,12 @@ IsLocalReferenceTableJoinPlan(PlannedStmt *plan)
{ {
bool hasReferenceTable = false; bool hasReferenceTable = false;
bool hasLocalTable = false; bool hasLocalTable = 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(GetLocalGroupId(), &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;
} }

View File

@ -17,6 +17,7 @@
#include "commands/dbcommands.h" #include "commands/dbcommands.h"
#include "distributed/hash_helpers.h" #include "distributed/hash_helpers.h"
#include "distributed/listutils.h" #include "distributed/listutils.h"
#include "distributed/master_protocol.h"
#include "distributed/metadata_cache.h" #include "distributed/metadata_cache.h"
#include "distributed/multi_client_executor.h" #include "distributed/multi_client_executor.h"
#include "distributed/worker_manager.h" #include "distributed/worker_manager.h"
@ -402,6 +403,39 @@ NodeIsPrimaryWorker(WorkerNode *node)
} }
/*
* CanUseCoordinatorLocalTablesWithReferenceTables returns true if we
* are allowed to use coordinator local tables with reference tables
* for joining or defining foreign keys between them.
*/
bool
CanUseCoordinatorLocalTablesWithReferenceTables(void)
{
/*
* Using local tables of coordinator with reference tables is only allowed
* if we are in the coordinator.
*
* Also, to check if coordinator can have reference table placements in below
* check, we should be in the coordinator.
*/
if (!IsCoordinator())
{
return false;
}
/*
* If reference table doesn't have placements on the coordinator, we don't
* use local tables in coordinator with reference tables.
*/
if (!CanHaveReferenceTablePlacements())
{
return false;
}
return true;
}
/* /*
* CanHaveReferenceTablePlacements returns true if current node can have * CanHaveReferenceTablePlacements returns true if current node can have
* reference table placements. This is only possible if we called below * reference table placements. This is only possible if we called below

View File

@ -72,6 +72,7 @@ extern WorkerNode * WorkerGetLocalFirstCandidateNode(List *currentNodeList);
extern uint32 ActivePrimaryWorkerNodeCount(void); extern uint32 ActivePrimaryWorkerNodeCount(void);
extern List * ActivePrimaryWorkerNodeList(LOCKMODE lockMode); extern List * ActivePrimaryWorkerNodeList(LOCKMODE lockMode);
extern List * ActivePrimaryNodeList(LOCKMODE lockMode); extern List * ActivePrimaryNodeList(LOCKMODE lockMode);
extern bool CanUseCoordinatorLocalTablesWithReferenceTables(void);
extern List * ReferenceTablePlacementNodeList(LOCKMODE lockMode); extern List * ReferenceTablePlacementNodeList(LOCKMODE lockMode);
extern List * DistributedTablePlacementNodeList(LOCKMODE lockMode); extern List * DistributedTablePlacementNodeList(LOCKMODE lockMode);
extern bool NodeCanHaveDistTablePlacements(WorkerNode *node); extern bool NodeCanHaveDistTablePlacements(WorkerNode *node);