diff --git a/src/backend/distributed/utils/foreign_key_relationship.c b/src/backend/distributed/utils/foreign_key_relationship.c index a63840d5f..8ae0dd7f2 100644 --- a/src/backend/distributed/utils/foreign_key_relationship.c +++ b/src/backend/distributed/utils/foreign_key_relationship.c @@ -146,6 +146,16 @@ GetForeignKeyConnectedRelationIdList(Oid relationId) bool ShouldUndistributeCitusLocalTable(Oid relationId) { + CitusTableCacheEntry *cacheEntry = GetCitusTableCacheEntry(relationId); + if (!cacheEntry->autoConverted) + { + /* + * The relation is not added to metadata automatically, + * we shouldn't undistribute it. + */ + return false; + } + /* * As we will operate on foreign key connected relations, here we * invalidate foreign key graph so that we act on fresh graph. @@ -171,15 +181,6 @@ ShouldUndistributeCitusLocalTable(Oid relationId) */ return false; } - CitusTableCacheEntry *cacheEntry = GetCitusTableCacheEntry(relationOid); - if (!cacheEntry->autoConverted) - { - /* - * The relation is connected to a (or, is a) Citus Local Table created - * by the user. We shouldn't undistribute it. - */ - return false; - } } return true;