From 0cbb6eee5ad182ea851aeacdb5a8020911c65bfb Mon Sep 17 00:00:00 2001 From: LuoGe Date: Wed, 30 Aug 2023 21:38:59 +0800 Subject: [PATCH] Update createplan.cpp --- src/gausskernel/optimizer/plan/createplan.cpp | 288 ++++++++++++++++++ 1 file changed, 288 insertions(+) diff --git a/src/gausskernel/optimizer/plan/createplan.cpp b/src/gausskernel/optimizer/plan/createplan.cpp index 000bcd610..11266d756 100755 --- a/src/gausskernel/optimizer/plan/createplan.cpp +++ b/src/gausskernel/optimizer/plan/createplan.cpp @@ -7141,6 +7141,24 @@ static void estimate_directHashjoin_Cost( join_plan->join.plan.plan_width = outer_width; } +/* + * function name: create_direct_hashjoin + * description: Creates a hash join plan node (HashJoin) for a direct hash join operation. + * arguments: + * - root: The planner's main data structure, containing various planning information. + * - outerPlan: The left subplan of the hash join. + * - innerPlan: The right subplan of the hash join. + * - tlist: The targetlist of the query, containing the list of target attributes. + * - joinClauses: List of join clauses. + * - joinType: The type of join to be performed (inner, left, right, full outer, etc.). + * return value: A pointer to the constructed hash join plan node (HashJoin). + * note: This function constructs a HashJoin plan node for a direct hash join operation by setting various attributes, + * including the targetlist, join clauses, left and right subtrees, and various other parameters. The cost + * estimation information should be estimated before using the constructed node. This node represents a plan that + * performs a hash join operation between the provided subplans. + * date: 2023/8/19 + * contact tel: 18720816902 + */ HashJoin* create_direct_hashjoin( PlannerInfo* root, Plan* outerPlan, Plan* innerPlan, List* tlist, List* joinClauses, JoinType joinType) { @@ -7243,6 +7261,19 @@ typedef struct replace_scan_clause_context { List* scan_clauses; } replace_scan_clause_context; +/* + * function name: replace_scan_clause_walker + * description: Walks through a parse tree node and replaces scan clauses with a new destination index. + * arguments: + * - node: The current node being processed in the parse tree. + * - context: Context information containing the destination index for replacement. + * return value: A boolean indicating whether the walk should continue (true) or stop (false). + * note: This function is used to traverse a parse tree and replace scan clauses with a specified destination index. + * It handles cases where the node is a Var (variable reference) and updates its varno to the new destination + * index. It also skips HashFilter nodes and continues the walk through other nodes. + * date: 2023/8/19 + * contact tel: 18720816902 + */ static bool replace_scan_clause_walker(Node* node, replace_scan_clause_context* context) { if (node == NULL) @@ -7259,6 +7290,19 @@ static bool replace_scan_clause_walker(Node* node, replace_scan_clause_context* return expression_tree_walker(node, (bool (*)())replace_scan_clause_walker, (void*)context); } +/* + * function name: replace_scan_clause + * description: Replaces scan clauses in a list with a new destination index. + * arguments: + * - scan_clauses: List of scan clauses to be processed. + * - idx: The new destination index for replacement. + * return value: A new list containing the scan clauses with updated destination index. + * note: This function takes a list of scan clauses and a new destination index. It walks through each scan clause in + * the list and uses the replace_scan_clause_walker function to replace Var nodes with the new destination index. + * The modified scan clauses are collected in a new list and returned. + * date: 2023/8/19 + * contact tel: 18720816902 + */ static List* replace_scan_clause(List* scan_clauses, Index idx) { replace_scan_clause_context context; @@ -7279,6 +7323,23 @@ static List* replace_scan_clause(List* scan_clauses, Index idx) return context.scan_clauses; } +/* + * function name: create_direct_scan + * description: Creates a scan plan for direct table access based on the specified table orientation. + * arguments: + * - root: The planner's main data structure, containing various planning information. + * - tlist: The targetlist of the query, containing the list of target attributes. + * - realResultRTE: The RangeTblEntry representing the table being accessed. + * - src_idx: The index of the source relation in the simple_rel_array. + * - dest_idx: The new destination index for replacement in scan clauses. + * return value: A pointer to the constructed scan plan. + * note: This function constructs a scan plan for direct table access based on the table's orientation (column-oriented, + * row-oriented, or timeseries-oriented). It generates the appropriate scan node (e.g., CStoreScan or SeqScan), + * sets targetlist and scan clauses, calculates costs, and handles partitioned tables. The plan is then configured + * for execution on datanodes and distributed based on the table's distribution keys. + * date: 2023/8/19 + * contact tel: 18720816902 + */ Plan* create_direct_scan(PlannerInfo* root, List* tlist, RangeTblEntry* realResultRTE, Index src_idx, Index dest_idx) { Plan* result = NULL; @@ -7422,6 +7483,24 @@ Plan* create_direct_righttree( return righttree; } +/* + * function name: make_hashjoin + * description: Creates a HashJoin plan node based on the provided information. + * arguments: + * - tlist: The targetlist of the query, containing the list of target attributes. + * - joinclauses: List of join clauses. + * - otherclauses: List of additional quals. + * - hashclauses: List of hash join clauses. + * - lefttree: The left subtree of the hash join. + * - righttree: The right subtree of the hash join. + * - jointype: The type of join to be performed (inner, left, right, full outer, etc.). + * return value: A pointer to the constructed HashJoin plan node. + * note: This function constructs a HashJoin plan node with the provided attributes, including targetlist, join clauses, + * other quals, hash join clauses, left and right subtrees, and join type. The cost should be set by the caller + * before using the constructed node. + * date: 2023/8/19 + * contact tel: 18720816902 + */ static HashJoin* make_hashjoin(List* tlist, List* joinclauses, List* otherclauses, List* hashclauses, Plan* lefttree, Plan* righttree, JoinType jointype) { @@ -7440,6 +7519,24 @@ static HashJoin* make_hashjoin(List* tlist, List* joinclauses, List* otherclause return node; } +/* + * function name: make_hash + * description: Creates a Hash plan node for hash-based join processing. + * arguments: + * - lefttree: The left subtree of the hash join. + * - skewTable: OID of the table to be used for skew optimization. + * - skewColumn: Attribute number of the column to be used for skew optimization. + * - skewInherit: Flag indicating whether skew optimization should inherit to child nodes. + * - skewColType: Data type OID of the skew column. + * - skewColTypmod: Type modifier of the skew column. + * return value: A pointer to the constructed Hash plan node. + * note: This function constructs a Hash plan node, which is used for hash-based join processing. It copies cost and + * size information from the input left subtree, sets the startup cost to be equal to the total cost for plausibility + * reasons, and includes information about skew optimization if provided. The constructed Hash node represents + * the hash-based join plan. + * date: 2023/8/19 + * contact tel: 18720816902 + */ static Hash* make_hash( Plan* lefttree, Oid skewTable, AttrNumber skewColumn, bool skewInherit, Oid skewColType, int32 skewColTypmod) { @@ -7472,6 +7569,28 @@ static Hash* make_hash( return node; } +/* + * function name: make_mergejoin + * description: Creates a MergeJoin plan node for merge join processing. + * arguments: + * - tlist: The targetlist of the query, containing the list of target attributes. + * - joinclauses: List of join clauses. + * - otherclauses: List of additional quals. + * - mergeclauses: List of merge join clauses. + * - mergefamilies: Array of operator families for merge join clauses. + * - mergecollations: Array of collations for merge join clauses. + * - mergestrategies: Array of merge strategies for merge join clauses. + * - mergenullsfirst: Array indicating whether NULLs come first for each merge join clause. + * - lefttree: The left subtree of the merge join. + * - righttree: The right subtree of the merge join. + * - jointype: The type of join to be performed (inner, left, right, full outer, etc.). + * return value: A pointer to the constructed MergeJoin plan node. + * note: This function constructs a MergeJoin plan node, which is used for merge join processing. It sets various attributes + * such as targetlist, join clauses, merge clauses, operator families, collations, strategies, NULLs ordering, + * left and right subtrees, and join type. The cost should be set by the caller before using the constructed node. + * date: 2023/8/19 + * contact tel: 18720816902 + */ static MergeJoin* make_mergejoin(List* tlist, List* joinclauses, List* otherclauses, List* mergeclauses, Oid* mergefamilies, Oid* mergecollations, int* mergestrategies, bool* mergenullsfirst, Plan* lefttree, Plan* righttree, JoinType jointype) @@ -8032,6 +8151,19 @@ Sort* make_sort_from_targetlist(PlannerInfo* root, Plan* lefttree, double limit_ } } +/* + * function name: make_material + * description: Creates a Material plan node for materializing intermediate results. + * arguments: + * - lefttree: The input plan subtree to be materialized. + * - materialize_all: Flag indicating whether to materialize all rows. + * return value: A pointer to the constructed Material plan node. + * note: This function constructs a Material plan node, which is used for materializing intermediate query results. + * It copies the targetlist and DOP (Degree of Parallelism) from the input plan, sets materialization properties, + * and inherits other relevant attributes. The cost should be set by the caller before using the constructed node. + * date: 2023/8/19 + * contact tel: 18720816902 + */ Material* make_material(Plan* lefttree, bool materialize_all) { Material* node = makeNode(Material); @@ -8133,6 +8265,35 @@ void adjust_all_pathkeys_by_agg_tlist(PlannerInfo* root, List* tlist, WindowList root->query_pathkeys = NIL; } +/* + * function name: make_agg + * description: Creates an Agg plan node for aggregate computation. + * arguments: + * - root: The planner's main data structure, containing various planning information. + * - tlist: The targetlist of the query, containing the list of target attributes. + * - qual: List of quals representing the aggregate filter (HAVING clause). + * - aggstrategy: The strategy for performing aggregation (PLAIN, SORTED, HASHED). + * - aggcosts: Cost information related to aggregation operations. + * - numGroupCols: The number of grouping columns. + * - grpColIdx: Array of attribute numbers representing grouping columns. + * - grpOperators: Array of operator OIDs for grouping columns. + * - numGroups: The estimated number of distinct groups. + * - lefttree: The input plan subtree for aggregation. + * - wflists: Window function information for optimization. + * - need_stream: Flag indicating whether stream plan is required. + * - trans_agg: Flag indicating if transition aggregates are present. + * - groupingSets: List of grouping sets. + * - hash_entry_size: Size of hash table entry for hash aggregation. + * - add_width: Flag indicating whether to add agg function width to total width. + * - agg_orientation: Orientation of aggregation (DISTINCT_INTENT, AGG_LEVEL_1_INTENT, etc.). + * - unique_check: Flag indicating whether unique check is required. + * return value: A pointer to the constructed Agg plan node. + * note: This function constructs an Agg plan node for performing aggregate computation. It sets various attributes such + * as targetlist, quals, grouping columns, strategies, estimated number of groups, distribution information, + * costs, and more. The constructed node represents the aggregation plan for execution. + * date: 2023/8/19 + * contact tel: 18720816902 + */ Agg* make_agg(PlannerInfo* root, List* tlist, List* qual, AggStrategy aggstrategy, const AggClauseCosts* aggcosts, int numGroupCols, AttrNumber* grpColIdx, Oid* grpOperators, long numGroups, Plan* lefttree, WindowLists* wflists, bool need_stream, bool trans_agg, List* groupingSets, Size hash_entry_size, bool add_width, @@ -8289,6 +8450,31 @@ Agg* make_agg(PlannerInfo* root, List* tlist, List* qual, AggStrategy aggstrateg return node; } +/* + * function name: make_windowagg + * description: Creates a WindowAgg plan node for window function computation. + * arguments: + * - root: The planner's main data structure, containing various planning information. + * - tlist: The targetlist of the query, containing the list of target attributes. + * - windowFuncs: List of window functions to be computed. + * - winref: Reference number for the window specification. + * - partNumCols: The number of partitioning columns. + * - partColIdx: Array of attribute numbers representing partitioning columns. + * - partOperators: Array of operator OIDs for partitioning columns. + * - ordNumCols: The number of ordering columns. + * - ordColIdx: Array of attribute numbers representing ordering columns. + * - ordOperators: Array of operator OIDs for ordering columns. + * - frameOptions: Options for defining the window frame. + * - startOffset: Starting offset for the window frame. + * - endOffset: Ending offset for the window frame. + * - lefttree: The input plan subtree for window function computation. + * return value: A pointer to the constructed WindowAgg plan node. + * note: This function constructs a WindowAgg plan node for performing window function computation. It sets various attributes + * such as targetlist, window function definitions, partitioning and ordering columns, frame options, distribution + * information, costs, and more. The constructed node represents the window function computation plan for execution. + * date: 2023/8/19 + * contact tel: 18720816902 + */ WindowAgg* make_windowagg(PlannerInfo* root, List* tlist, List* windowFuncs, Index winref, int partNumCols, AttrNumber* partColIdx, Oid* partOperators, int ordNumCols, AttrNumber* ordColIdx, Oid* ordOperators, int frameOptions, Node* startOffset, Node* endOffset, Plan* lefttree) @@ -8342,6 +8528,25 @@ WindowAgg* make_windowagg(PlannerInfo* root, List* tlist, List* windowFuncs, Ind return node; } +/* + * function name: make_group + * description: Creates a Group plan node for grouping operation. + * arguments: + * - root: The planner's main data structure, containing various planning information. + * - tlist: The targetlist of the query, containing the list of target attributes. + * - qual: List of quals representing the grouping filter (HAVING clause). + * - numGroupCols: The number of grouping columns. + * - grpColIdx: Array of attribute numbers representing grouping columns. + * - grpOperators: Array of operator OIDs for grouping columns. + * - numGroups: The estimated number of distinct groups. + * - lefttree: The input plan subtree for grouping operation. + * return value: A pointer to the constructed Group plan node. + * note: This function constructs a Group plan node for performing grouping operation. It sets various attributes such as + * targetlist, quals, grouping columns, estimated number of groups, distribution information, costs, and more. + * The constructed node represents the grouping operation plan for execution. + * date: 2023/8/19 + * contact tel: 18720816902 + */ Group* make_group(PlannerInfo* root, List* tlist, List* qual, int numGroupCols, AttrNumber* grpColIdx, Oid* grpOperators, double numGroups, Plan* lefttree) { @@ -8748,6 +8953,18 @@ static Plan* parallel_limit_sort( return plan; } +/* + * function name: create_offset_count + * description: Creates a new Node with an offset/count value. + * arguments: + * - offsetCount: Node representing an offset/count value (optional). + * - value: The value to assign to the offset/count node. + * return value: A pointer to the newly created Node. + * note: This function creates a new Node with an offset/count value, typically used in window function frames. + * It checks the type of the input offsetCount and constructs a new Node accordingly. + * date: 2023/8/19 + * contact tel: 18720816902 + */ static Node* create_offset_count(Node* offsetCount, Datum value) { Node* node = NULL; @@ -9157,6 +9374,19 @@ BaseResult* make_result(PlannerInfo* root, List* tlist, Node* resconstantqual, P return node; } +/* + * function name: FindForeignScan + * description: Searches for a ForeignScan node within the given Plan tree. + * arguments: + * - plan: The root of the Plan tree to search within. + * return value: A pointer to the found ForeignScan node, or NULL if not found. + * note: This function recursively searches through the given Plan tree and its subplans for a ForeignScan node. + * If a ForeignScan node is found, it checks whether the scan relates to certain types of foreign tables. + * If yes, it returns NULL to indicate that further optimization should not be applied on this node. + * Otherwise, it returns the pointer to the found ForeignScan node, allowing further optimization. + * date: 2023/8/19 + * contact tel: 18720816902 + */ static Plan* FindForeignScan(Plan* plan) { Plan* result = NULL; @@ -9239,6 +9469,18 @@ static Plan* FindForeignScan(Plan* plan) return result; } +/* + * function name: getDistSessionKey + * description: Retrieves the distributed session key from the given list of FDW private data. + * arguments: + * - fdw_private: List of FDW private data containing information for a foreign table scan. + * return value: The distributed session key value retrieved from the FDW private data. + * note: This function iterates through the given FDW private data list and extracts the distributed session key. + * The session key is usually stored as a "DefElem" with the name "session_key" within the list. + * It returns the retrieved distributed session key value, which can be used for further processing. + * date: 2023/8/19 + * contact tel: 18720816902 + */ #ifdef STREAMPLAN uint32 getDistSessionKey(List* fdw_private) { @@ -9267,6 +9509,21 @@ uint32 getDistSessionKey(List* fdw_private) } #endif +/* + * function name: PlanForeignModify + * description: Constructs private plan data for each foreign table result relation in a ModifyTable node. + * arguments: + * - root: The planner's main data structure, containing various planning information. + * - node: The ModifyTable node representing the modify operation (INSERT/UPDATE/DELETE). + * - resultRelations: List of indexes representing result relations to be modified. + * return value: None (void function). + * note: This function iterates through the list of result relations in a ModifyTable node that correspond to + * foreign tables. It retrieves the FdwRoutine for each relation and invokes the PlanForeignModify function + * provided by the FDW. The private plan data returned by the FDW is accumulated into a list and assigned to + * the fdwPrivLists field of the ModifyTable node for later use during execution. + * date: 2023/8/19 + * contact tel: 18720816902 + */ static void PlanForeignModify(PlannerInfo* root, ModifyTable* node, List* resultRelations) { List* fdw_private_list = NIL; @@ -10232,6 +10489,19 @@ RowToVec* make_rowtovec(Plan* lefttree) return node; } +/* + * function name: make_vectorow + * description: Creates a VecToRow plan node to convert vectorized output to row format. + * arguments: + * - lefttree: The input plan subtree that produces vectorized output. + * return value: A pointer to the constructed VecToRow plan node. + * note: This function constructs a VecToRow plan node, which is used to convert vectorized output + * into row format. It inherits various attributes and costs from the input plan and sets up + * the necessary information for the VecToRow node. The VecToRow node is typically used in vectorized + * execution plans. + * date: 2023/8/19 + * contact tel: 18720816902 + */ VecToRow* make_vectorow(Plan* lefttree) { VecToRow* node = makeNode(VecToRow); @@ -10394,6 +10664,24 @@ Plan* make_stream_plan( return plan; } +/* + * function name: make_redistribute_for_agg + * description: Creates a redistribution plan node for aggregation operations. + * arguments: + * - root: The planner's main data structure, containing various planning information. + * - lefttree: The input plan subtree for aggregation. + * - redistribute_keys: List of keys used for redistribution. + * - multiple: Cost multiple factor for the plan. + * - distribution: Distribution information for the plan (NULL if needs to be determined). + * - is_local_redistribute: Flag indicating if local redistribution is preferred. + * return value: A pointer to the constructed redistribution plan node. + * note: This function constructs a Stream plan node with the STREAM_REDISTRIBUTE type, typically used for + * redistributing data for aggregation operations. It sets various attributes including redistribution keys, + * distribution, targetlist, costs, parallelism, and more. The constructed node represents a redistribution + * operation in the execution plan. + * date: 2023/8/19 + * contact tel: 18720816902 + */ Plan* make_redistribute_for_agg(PlannerInfo* root, Plan* lefttree, List* redistribute_keys, double multiple, Distribution* distribution, bool is_local_redistribute) { -- 2.34.1