diff --git a/src/backend/distributed/planner/combine_query_planner.c b/src/backend/distributed/planner/combine_query_planner.c index 5dc533a7f..c8ab2a4b3 100644 --- a/src/backend/distributed/planner/combine_query_planner.c +++ b/src/backend/distributed/planner/combine_query_planner.c @@ -316,36 +316,6 @@ BuildSelectStatementViaStdPlanner(Query *combineQuery, List *remoteScanTargetLis } -/* - * ExtractCitusExtradataContainerRTE is a helper function that stores rangeTblEntry - * to result if it has citus extra data container. - * - * The function returns true if it finds the RTE, and false otherwise. - */ -bool -ExtractCitusExtradataContainerRTE(RangeTblEntry *rangeTblEntry, RangeTblEntry **result) -{ - if (rangeTblEntry->rtekind == RTE_FUNCTION && - list_length(rangeTblEntry->functions) == 1) - { - RangeTblFunction *rangeTblFunction = (RangeTblFunction *) linitial( - rangeTblEntry->functions); - if (!IsA(rangeTblFunction->funcexpr, FuncExpr)) - { - return false; - } - FuncExpr *funcExpr = castNode(FuncExpr, rangeTblFunction->funcexpr); - if (funcExpr->funcid == CitusExtraDataContainerFuncId()) - { - *result = rangeTblEntry; - return true; - } - } - - return false; -} - - /* * Finds the rangetable entry in the query that refers to the citus_extradata_container * and stores the pointer in result. @@ -361,7 +331,25 @@ FindCitusExtradataContainerRTE(Node *node, RangeTblEntry **result) if (IsA(node, RangeTblEntry)) { RangeTblEntry *rangeTblEntry = castNode(RangeTblEntry, node); - return ExtractCitusExtradataContainerRTE(rangeTblEntry, result); + if (rangeTblEntry->rtekind == RTE_FUNCTION && + list_length(rangeTblEntry->functions) == 1) + { + RangeTblFunction *rangeTblFunction = (RangeTblFunction *) linitial( + rangeTblEntry->functions); + if (!IsA(rangeTblFunction->funcexpr, FuncExpr)) + { + return false; + } + FuncExpr *funcExpr = castNode(FuncExpr, rangeTblFunction->funcexpr); + if (funcExpr->funcid == CitusExtraDataContainerFuncId()) + { + *result = rangeTblEntry; + return true; + } + } + + /* query_tree_walker descends into RTEs */ + return false; } else if (IsA(node, Query)) { diff --git a/src/backend/distributed/utils/distribution_column.c b/src/backend/distributed/utils/distribution_column.c index 181a2a734..5927be612 100644 --- a/src/backend/distributed/utils/distribution_column.c +++ b/src/backend/distributed/utils/distribution_column.c @@ -282,29 +282,3 @@ ColumnToColumnName(Oid relationId, Node *columnNode) return columnName; } - - -/* - * GetAttrNumForMatchingColumn returns the attribute number for the column - * in the target relation that matches the given Var. If the column does not - * exist or is not comparable, it returns InvalidAttrNumber. - */ -AttrNumber -GetAttrNumForMatchingColumn(RangeTblEntry *rteTarget, Oid relid, Var *var) -{ - char *targetColumnName = get_attname(relid, var->varattno, false); - AttrNumber attnum = get_attnum(rteTarget->relid, targetColumnName); - if (attnum == InvalidAttrNumber) - { - ereport(DEBUG5, (errmsg("Column %s does not exist in relation %s", - targetColumnName, rteTarget->eref->aliasname))); - return InvalidAttrNumber; - } - if(var->vartype != get_atttype(rteTarget->relid, attnum)) - { - ereport(DEBUG5, (errmsg("Column %s is not comparable for tables with relids %d and %d", - targetColumnName, rteTarget->relid, relid))); - return InvalidAttrNumber; - } - return attnum; -} diff --git a/src/backend/distributed/utils/query_utils.c b/src/backend/distributed/utils/query_utils.c index aa6f76659..ac33bdd52 100644 --- a/src/backend/distributed/utils/query_utils.c +++ b/src/backend/distributed/utils/query_utils.c @@ -15,14 +15,10 @@ #include "catalog/pg_class.h" #include "nodes/nodeFuncs.h" #include "nodes/primnodes.h" -#include "parser/parsetree.h" -#include "distributed/deparse_shard_query.h" #include "distributed/listutils.h" #include "distributed/query_utils.h" -#include "distributed/relation_restriction_equivalence.h" #include "distributed/version_compat.h" -#include "utils/lsyscache.h" static bool CitusQueryableRangeTableRelation(RangeTblEntry *rangeTableEntry); @@ -182,94 +178,3 @@ ExtractRangeTableIndexWalker(Node *node, List **rangeTableIndexList) return walkerResult; } - - -/* - * ExtractRangeTableIds walks over the given node, and finds all range - * table entries. - */ -bool -ExtractRangeTableIds(Node *node, ExtractRangeTableIdsContext *context) -{ - List **rangeTableList = context->idList; - List *rtable = context->rtable; - - if (node == NULL) - { - return false; - } - - if (IsA(node, RangeTblRef)) - { - int rangeTableIndex = ((RangeTblRef *) node)->rtindex; - - RangeTblEntry *rte = rt_fetch(rangeTableIndex, rtable); - if (rte->rtekind == RTE_SUBQUERY) - { - Query *subquery = rte->subquery; - context->rtable = subquery->rtable; - ExtractRangeTableIds((Node *) subquery, context); - context->rtable = rtable; /* restore original rtable */ - } - else if (rte->rtekind == RTE_RELATION || rte->rtekind == RTE_FUNCTION) - { - (*rangeTableList) = lappend(*rangeTableList, rte); - ereport(DEBUG4, (errmsg("ExtractRangeTableIds: found range table id %d", rte->relid))); - } - else - { - ereport(DEBUG4, (errmsg("Unsupported RTE kind in ExtractRangeTableIds %d", rte->rtekind))); - } - return false; - } - else if (IsA(node, Query)) - { - context->rtable = ((Query *) node)->rtable; - query_tree_walker((Query *) node, ExtractRangeTableIds, context, 0); - context->rtable = rtable; /* restore original rtable */ - return false; - } - else - { - return expression_tree_walker(node, ExtractRangeTableIds, context); - } -} - - -/* - * CheckIfAllCitusRTEsAreColocated checks if all distributed tables in the - * given node are colocated. If they are, it sets the value of rte to a - * representative table. - */ -bool -CheckIfAllCitusRTEsAreColocated(Node *node, List *rtable, RangeTblEntry **rte, List **citusRelids) -{ - ExtractRangeTableIdsContext context; - List *idList = NIL; - context.idList = &idList; - context.rtable = rtable; - ExtractRangeTableIds(node, &context); - - RangeTblEntry *rteTmp; - ListCell *lc = NULL; - - foreach(lc, idList) - { - rteTmp = (RangeTblEntry *) lfirst(lc); - if (IsCitusTable(rteTmp->relid)) - { - *citusRelids = lappend_int(*citusRelids, rteTmp->relid); - *rte = rteTmp; // set the value of rte, a representative table - } - } - - if (!AllDistributedRelationsInListColocated(citusRelids)) - { - ereport(DEBUG5, (errmsg("The distributed tables are not colocated"))); - return false; - } - - return true; -} - - diff --git a/src/include/distributed/combine_query_planner.h b/src/include/distributed/combine_query_planner.h index 6fc4413ab..2afc8aa5f 100644 --- a/src/include/distributed/combine_query_planner.h +++ b/src/include/distributed/combine_query_planner.h @@ -26,7 +26,6 @@ extern Path * CreateCitusCustomScanPath(PlannerInfo *root, RelOptInfo *relOptInf CustomScan *remoteScan); extern PlannedStmt * PlanCombineQuery(struct DistributedPlan *distributedPlan, struct CustomScan *dataScan); -extern bool ExtractCitusExtradataContainerRTE(RangeTblEntry *rangeTblEntry, RangeTblEntry **result); extern bool FindCitusExtradataContainerRTE(Node *node, RangeTblEntry **result); extern bool ReplaceCitusExtraDataContainer; extern CustomScan *ReplaceCitusExtraDataContainerWithCustomScan; diff --git a/src/include/distributed/distribution_column.h b/src/include/distributed/distribution_column.h index 58679fa47..a7ec6a593 100644 --- a/src/include/distributed/distribution_column.h +++ b/src/include/distributed/distribution_column.h @@ -25,6 +25,5 @@ extern Var * BuildDistributionKeyFromColumnName(Oid relationId, extern char * ColumnToColumnName(Oid relationId, Node *columnNode); extern Oid ColumnTypeIdForRelationColumnName(Oid relationId, char *columnName); extern void EnsureValidDistributionColumn(Oid relationId, char *columnName); -extern AttrNumber GetAttrNumForMatchingColumn(RangeTblEntry *rteTarget, Oid relid, Var *var); #endif /* DISTRIBUTION_COLUMN_H */ diff --git a/src/include/distributed/query_utils.h b/src/include/distributed/query_utils.h index c3e20d14e..0b216d158 100644 --- a/src/include/distributed/query_utils.h +++ b/src/include/distributed/query_utils.h @@ -30,13 +30,6 @@ typedef struct ExtractRangeTableWalkerContext ExtractRangeTableMode walkerMode; } ExtractRangeTableWalkerContext; -/* Struct to pass rtable list and the result list to walker */ -typedef struct ExtractRangeTableIdsContext -{ - List **idList; - List *rtable; -} ExtractRangeTableIdsContext; - /* Function declarations for query-walker utility functions */ extern bool ExtractRangeTableList(Node *node, ExtractRangeTableWalkerContext *context); @@ -45,6 +38,5 @@ extern bool ExtractRangeTableRelationWalker(Node *node, List **rangeTableList); extern bool ExtractRangeTableEntryWalker(Node *node, List **rangeTableList); extern bool ExtractRangeTableIndexWalker(Node *node, List **rangeTableIndexList); -extern bool ExtractRangeTableIds(Node *node, ExtractRangeTableIdsContext *context); -extern bool CheckIfAllCitusRTEsAreColocated(Node *node, List *rtable, RangeTblEntry **rte, List **citusRelids); + #endif /* QUERY_UTILS_H */