mirror of https://github.com/citusdata/citus.git
Create new function AnyConnectedRelationIsNotAutoConverted
parent
09996f8401
commit
faee21bff9
|
|
@ -79,6 +79,8 @@ static bool RelationIdListContainsCitusTableType(List *relationIdList,
|
||||||
static bool RelationIdListContainsPostgresTable(List *relationIdList);
|
static bool RelationIdListContainsPostgresTable(List *relationIdList);
|
||||||
static void ConvertPostgresLocalTablesToCitusLocalTables(
|
static void ConvertPostgresLocalTablesToCitusLocalTables(
|
||||||
AlterTableStmt *alterTableStatement);
|
AlterTableStmt *alterTableStatement);
|
||||||
|
static bool AnyConnectedRelationIsNotAutoConverted(List *relationRangeVarList,
|
||||||
|
AlterTableStmt *alterTableStatement);
|
||||||
static int CompareRangeVarsByOid(const void *leftElement, const void *rightElement);
|
static int CompareRangeVarsByOid(const void *leftElement, const void *rightElement);
|
||||||
static List * GetAlterTableAddFKeyRightRelationIdList(
|
static List * GetAlterTableAddFKeyRightRelationIdList(
|
||||||
AlterTableStmt *alterTableStatement);
|
AlterTableStmt *alterTableStatement);
|
||||||
|
|
@ -1296,35 +1298,17 @@ ConvertPostgresLocalTablesToCitusLocalTables(AlterTableStmt *alterTableStatement
|
||||||
relationRangeVarList = SortList(relationRangeVarList, CompareRangeVarsByOid);
|
relationRangeVarList = SortList(relationRangeVarList, CompareRangeVarsByOid);
|
||||||
|
|
||||||
bool autoConverted = true;
|
bool autoConverted = true;
|
||||||
RangeVar *relationRangeVar;
|
|
||||||
foreach_ptr(relationRangeVar, relationRangeVarList)
|
if (AnyConnectedRelationIsNotAutoConverted(relationRangeVarList, alterTableStatement))
|
||||||
{
|
{
|
||||||
/*
|
autoConverted = false;
|
||||||
* Here we iterate the relation list, and if at least one of the relations
|
|
||||||
* is marked as not-auto-converted, we should mark all of them as
|
|
||||||
* not-auto-converted. In that case, we set the local variable autoConverted
|
|
||||||
* to false here, to later use it when converting relations.
|
|
||||||
*/
|
|
||||||
List *commandList = alterTableStatement->cmds;
|
|
||||||
LOCKMODE lockMode = AlterTableGetLockLevel(commandList);
|
|
||||||
bool missingOk = alterTableStatement->missing_ok;
|
|
||||||
Oid relationId = RangeVarGetRelid(relationRangeVar, lockMode, missingOk);
|
|
||||||
if (OidIsValid(relationId) && IsCitusTable(relationId) &&
|
|
||||||
IsCitusTableType(relationId, CITUS_LOCAL_TABLE))
|
|
||||||
{
|
|
||||||
CitusTableCacheEntry *entry = GetCitusTableCacheEntry(relationId);
|
|
||||||
if (!entry->autoConverted)
|
|
||||||
{
|
|
||||||
autoConverted = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Here we should operate on RangeVar objects since relations oid's would
|
* Here we should operate on RangeVar objects since relations oid's would
|
||||||
* change in below loop due to CreateCitusLocalTable.
|
* change in below loop due to CreateCitusLocalTable.
|
||||||
*/
|
*/
|
||||||
|
RangeVar *relationRangeVar;
|
||||||
foreach_ptr(relationRangeVar, relationRangeVarList)
|
foreach_ptr(relationRangeVar, relationRangeVarList)
|
||||||
{
|
{
|
||||||
List *commandList = alterTableStatement->cmds;
|
List *commandList = alterTableStatement->cmds;
|
||||||
|
|
@ -1417,6 +1401,43 @@ ConvertPostgresLocalTablesToCitusLocalTables(AlterTableStmt *alterTableStatement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* AnyConnectedRelationIsNotAutoConverted takes a list of relations and returns true
|
||||||
|
* if any of these relations is marked as auto-converted = false. Returns true otherwise.
|
||||||
|
* This function also takes the current alterTableStatement command, to obtain the
|
||||||
|
* necessary locks.
|
||||||
|
*/
|
||||||
|
static bool
|
||||||
|
AnyConnectedRelationIsNotAutoConverted(List *relationRangeVarList,
|
||||||
|
AlterTableStmt *alterTableStatement)
|
||||||
|
{
|
||||||
|
RangeVar *relationRangeVar;
|
||||||
|
foreach_ptr(relationRangeVar, relationRangeVarList)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Here we iterate the relation list, and if at least one of the relations
|
||||||
|
* is marked as not-auto-converted, we should mark all of them as
|
||||||
|
* not-auto-converted. In that case, we return true here.
|
||||||
|
*/
|
||||||
|
List *commandList = alterTableStatement->cmds;
|
||||||
|
LOCKMODE lockMode = AlterTableGetLockLevel(commandList);
|
||||||
|
bool missingOk = alterTableStatement->missing_ok;
|
||||||
|
Oid relationId = RangeVarGetRelid(relationRangeVar, lockMode, missingOk);
|
||||||
|
if (OidIsValid(relationId) && IsCitusTable(relationId) &&
|
||||||
|
IsCitusTableType(relationId, CITUS_LOCAL_TABLE))
|
||||||
|
{
|
||||||
|
CitusTableCacheEntry *entry = GetCitusTableCacheEntry(relationId);
|
||||||
|
if (!entry->autoConverted)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CompareRangeVarsByOid is a comparison function to sort RangeVar object list.
|
* CompareRangeVarsByOid is a comparison function to sort RangeVar object list.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue