Dont auto-undistribute user-added citus local tables - Refactor

talha_tes1
Ahmet Gedemenli 2021-09-22 17:41:40 +03:00
parent f4297f774a
commit 2cfac21382
3 changed files with 23 additions and 12 deletions

View File

@ -95,7 +95,7 @@ static void IncrementUtilityHookCountersIfNecessary(Node *parsetree);
static void PostStandardProcessUtility(Node *parsetree); static void PostStandardProcessUtility(Node *parsetree);
static void DecrementUtilityHookCountersIfNecessary(Node *parsetree); static void DecrementUtilityHookCountersIfNecessary(Node *parsetree);
static bool IsDropSchemaOrDB(Node *parsetree); static bool IsDropSchemaOrDB(Node *parsetree);
static bool ShouldUndistributeCitusLocalTables(void); static bool ShouldCheckUndistributeCitusLocalTables(void);
/* /*
@ -271,7 +271,7 @@ multi_ProcessUtility(PlannedStmt *pstmt,
* can happen due to various kinds of drop commands, we immediately * can happen due to various kinds of drop commands, we immediately
* undistribute them at the end of the command. * undistribute them at the end of the command.
*/ */
if (ShouldUndistributeCitusLocalTables()) if (ShouldCheckUndistributeCitusLocalTables())
{ {
UndistributeDisconnectedCitusLocalTables(); UndistributeDisconnectedCitusLocalTables();
} }
@ -687,7 +687,8 @@ ProcessUtilityInternal(PlannedStmt *pstmt,
/* /*
* UndistributeDisconnectedCitusLocalTables undistributes citus local tables that * UndistributeDisconnectedCitusLocalTables undistributes citus local tables that
* are not connected to any reference tables via their individual foreign key * are not connected to any reference tables via their individual foreign key
* subgraphs. * subgraphs. Note that this function undistributes only the auto-converted tables,
* i.e the ones that are converted by Citus by cascading through foreign keys.
*/ */
void void
UndistributeDisconnectedCitusLocalTables(void) UndistributeDisconnectedCitusLocalTables(void)
@ -720,7 +721,7 @@ UndistributeDisconnectedCitusLocalTables(void)
continue; continue;
} }
if (ConnectedToReferenceTableViaFKey(citusLocalTableId)) if (!ShouldUndistributeCitusLocalTable(citusLocalTableId))
{ {
/* still connected to a reference table, skip it */ /* still connected to a reference table, skip it */
UnlockRelationOid(citusLocalTableId, lockMode); UnlockRelationOid(citusLocalTableId, lockMode);
@ -751,11 +752,11 @@ UndistributeDisconnectedCitusLocalTables(void)
/* /*
* ShouldUndistributeCitusLocalTables returns true if we might need to check * ShouldCheckUndistributeCitusLocalTables returns true if we might need to check
* citus local tables for their connectivity to reference tables. * citus local tables for undistributing automatically.
*/ */
static bool static bool
ShouldUndistributeCitusLocalTables(void) ShouldCheckUndistributeCitusLocalTables(void)
{ {
if (!ConstraintDropped) if (!ConstraintDropped)
{ {

View File

@ -139,11 +139,12 @@ GetForeignKeyConnectedRelationIdList(Oid relationId)
/* /*
* ConnectedToReferenceTableViaFKey returns true if given relationId is * ShouldUndistributeCitusLocalTable returns true if given relationId needs
* connected to a reference table via its foreign key subgraph. * to be undistributed. Here we do not undistribute table if it's converted by the user,
* or connected to a table converted by the user, or a reference table, via foreign keys.
*/ */
bool bool
ConnectedToReferenceTableViaFKey(Oid relationId) ShouldUndistributeCitusLocalTable(Oid relationId)
{ {
/* /*
* As we will operate on foreign key connected relations, here we * As we will operate on foreign key connected relations, here we
@ -152,7 +153,16 @@ ConnectedToReferenceTableViaFKey(Oid relationId)
InvalidateForeignKeyGraph(); InvalidateForeignKeyGraph();
List *fkeyConnectedRelations = GetForeignKeyConnectedRelationIdList(relationId); List *fkeyConnectedRelations = GetForeignKeyConnectedRelationIdList(relationId);
return RelationIdListHasReferenceTable(fkeyConnectedRelations); Oid relationOid = InvalidOid;
foreach_oid(relationOid, fkeyConnectedRelations)
{
if (IsCitusTableType(relationOid, REFERENCE_TABLE))
{
return false;
}
}
return true;
} }

View File

@ -16,7 +16,7 @@
#include "nodes/primnodes.h" #include "nodes/primnodes.h"
extern List * GetForeignKeyConnectedRelationIdList(Oid relationId); extern List * GetForeignKeyConnectedRelationIdList(Oid relationId);
extern bool ConnectedToReferenceTableViaFKey(Oid relationId); extern bool ShouldUndistributeCitusLocalTable(Oid relationId);
extern List * ReferencedRelationIdList(Oid relationId); extern List * ReferencedRelationIdList(Oid relationId);
extern List * ReferencingRelationIdList(Oid relationId); extern List * ReferencingRelationIdList(Oid relationId);
extern void SetForeignConstraintRelationshipGraphInvalid(void); extern void SetForeignConstraintRelationshipGraphInvalid(void);