对查询优化器所在目录下rewrite文件夹和path文件夹内一些重要函数的注释 #25
|
|
@ -109,6 +109,21 @@ static void updateRelOptInfoMinSecurity(RelOptInfo* rel);
|
|||
static void find_index_path(RelOptInfo* rel);
|
||||
static void bitmap_path_walker(Path* path);
|
||||
|
||||
/*
|
||||
function name: check_func_walker
|
||||
description: This function recursively traverses an expression tree to determine if there are any FuncExpr nodes present.
|
||||
arguments: The first argument represents the current node in the expression tree.
|
||||
The second argument indicates the pointer to a boolean variable that indicates whether a function call node has been found.
|
||||
return value: Returns true if a FuncExpr node is found, otherwise returns false. The "found" variable is modified accordingly to indicate the presence of a FuncExpr node during the traversal.
|
||||
note: The main process is as follows:
|
||||
-> Recursively traverses the given expression tree, examining each node.
|
||||
-> If the current node is NULL, it returns `false`.
|
||||
-> If the node is of type `FuncExpr` (function call node), sets the `found` variable to `true` and returns `true`.
|
||||
-> Otherwise, invokes the general expression tree walker `expression_tree_walker` to traverse child nodes, passing along the `found` variable.
|
||||
-> Returns a boolean value indicating whether a function call node was found in the expression tree.
|
||||
date: 2023/8/12
|
||||
contact tel: 18720816902
|
||||
*/
|
||||
static bool check_func_walker(Node* node, bool* found)
|
||||
{
|
||||
if (node == NULL) {
|
||||
|
|
@ -421,6 +436,22 @@ static bool reduce_predpush_broadcast(PlannerInfo* root, Path *path)
|
|||
return reduce;
|
||||
}
|
||||
|
||||
/*
|
||||
function name: make_predpush_subpath
|
||||
description: This function is responsible for generating a subpath for predicate pushdown. It extracts restriction conditions from the given relation's restrictinfo and creates a new subpath incorporating these conditions.
|
||||
arguments: The first argument represents the pointer of a PlannerInfo structure containing query planner context.
|
||||
The second argument indicates the RelOptInfo structure containing information about the relation being optimized.
|
||||
The third argument indicates the Path to be processed.
|
||||
return value: Returns the newly generated subpath that incorporates the extracted restriction conditions and supports predicate pushdown optimization. This function plays a role in query optimization, enhancing the execution plan by considering relevant conditions during subpath creation.
|
||||
note: The main process is as follows:
|
||||
-> Initialize the "quals" list to hold restriction conditions.
|
||||
-> Iterate through the "subplanrestrictinfo" list within the given "rel", which contains restriction information.
|
||||
-> If the condition "SUBQUERY_PREDPUSH(root)" is met, collect upper-level parameter IDs using the "collect_param_clause" function from the condition expressions.
|
||||
-> Create a new subpath "subpath" using the "create_result_path" function, passing in "root", "rel", "quals", "path", and "upper_params" as arguments.
|
||||
-> Return the newly created subpath "subpath".
|
||||
date: 2023/8/13
|
||||
contact tel: 18720816902
|
||||
*/
|
||||
static Path *make_predpush_subpath(PlannerInfo* root, RelOptInfo* rel, Path *path)
|
||||
{
|
||||
List* quals = NULL;
|
||||
|
|
@ -859,6 +890,19 @@ static void set_rel_pathlist(PlannerInfo* root, RelOptInfo* rel, Index rti, Rang
|
|||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
function name: SetPlainReSizeWithPruningRatio
|
||||
description: This function adjusts the estimated size of a partitioned relation and its associated indexes based on a pruning ratio. It modifies the estimated number of pages in the relation and its indexes to reflect the effect of pruning.
|
||||
arguments: The first argument represents the pointer to the RelOptInfo structure representing the partitioned relation.
|
||||
The second argument indicates the ratio by which to adjust the estimated size due to pruning.
|
||||
return value: This function does not return a value; it directly modifies the estimated page counts for the partitioned relation and its indexes based on the provided pruning ratio. The adjustment accounts for the pruning effect on the size estimates, contributing to accurate query planning and optimization for partitioned tables.
|
||||
note: The main process is as follows:
|
||||
-> Validate that the given relation is a partitioned table (assertion).
|
||||
-> Update the estimated number of pages in the partitioned relation by multiplying it with the given pruningRatio and applying a clamp function (clamp_row_est).
|
||||
-> Iterate through the list of indexes associated with the partitioned relation.
|
||||
date: 2023/8/13
|
||||
contact tel: 18720816902
|
||||
*/
|
||||
static void SetPlainReSizeWithPruningRatio(RelOptInfo *rel, double pruningRatio)
|
||||
{
|
||||
ListCell *cell = NULL;
|
||||
|
|
@ -2190,6 +2234,27 @@ static bool has_multiple_baserels(PlannerInfo* root)
|
|||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
function name: can_push_qual_into_subquery
|
||||
description: This function determines whether a restriction condition can be pushed into a subquery. It evaluates various criteria including pseudoconstant, security barrier, safe pushdown conditions, and partial push conditions to make this determination.
|
||||
arguments:
|
||||
- `root`: PlannerInfo context for query planning.
|
||||
- `rinfo`: RestrictInfo representing the restriction condition.
|
||||
- `rte`: RangeTblEntry representing the table entry.
|
||||
- `rti`: Index of the range table entry.
|
||||
- `clause`: The restriction condition expression to be evaluated.
|
||||
- `unsafeColumns`: A boolean array indicating the presence of unsafe columns.
|
||||
return value: A boolean value indicating whether the given restriction condition can be pushed into a subquery. This function is utilized in query planning to make informed decisions about optimization strategies, ensuring that the pushdown of restriction conditions is performed while considering multiple crucial factors.
|
||||
note: The main process is as follows:
|
||||
-> Retrieve the subquery from the RangeTblEntry `rte`.
|
||||
-> Check the `pseudoconstant` property of the RestrictInfo. If true, return `false`, indicating the restriction condition cannot be pushed.
|
||||
-> If the `security_barrier` property of the RangeTblEntry is true and the restriction condition contains leaky functions (`contain_leaky_functions`), return `false`.
|
||||
-> Call the `qual_is_pushdown_safe` function to assess whether the restriction condition can be safely pushed into the subquery.
|
||||
-> Call the `qual_pushdown_in_partialpush` function to determine whether the restriction condition can be pushed under partial push conditions.
|
||||
-> Return `true` if all checks are satisfied, indicating that the restriction condition can be pushed into the subquery.
|
||||
date: 2023/8/13
|
||||
contact tel: 18720816902
|
||||
*/
|
||||
static bool can_push_qual_into_subquery(PlannerInfo* root,
|
||||
RestrictInfo* rinfo,
|
||||
RangeTblEntry* rte,
|
||||
|
|
@ -2229,6 +2294,22 @@ typedef struct trans_lateral_vars_t
|
|||
int levelsup;
|
||||
}trans_lateral_vars_t;
|
||||
|
||||
/*
|
||||
function name: trans_lateral_vars_mutator
|
||||
description: This function recursively traverses an expression tree and performs transformations on Var nodes based on the given lateral_vars information. It handles the conversion of inner Vars to subquery form and outer Vars to Params.
|
||||
arguments:
|
||||
- `node`: The current node being processed in the expression tree.
|
||||
- `lateral_vars`: A structure containing information about the transformation process.
|
||||
return value: A modified expression tree with transformed Var nodes.
|
||||
note: The main process is as follows:
|
||||
-> If the node is NULL, return NULL.
|
||||
-> If the node is a Var:
|
||||
- If it's an inner Var (varno matches lateral_vars->rti), convert it to subquery form using target_list and return the transformed expression.
|
||||
- If it's an outer Var, convert it to Param by adjusting varlevelsup and return the new Var.
|
||||
-> Recursively traverse the expression tree using expression_tree_mutator, applying the trans_lateral_vars_mutator function.
|
||||
date: 2023/8/13
|
||||
contact tel: 18720816902
|
||||
*/
|
||||
static Node* trans_lateral_vars_mutator(Node *node, trans_lateral_vars_t *lateral_vars)
|
||||
{
|
||||
if (node == NULL)
|
||||
|
|
@ -2261,6 +2342,21 @@ static Node* trans_lateral_vars_mutator(Node *node, trans_lateral_vars_t *latera
|
|||
(Node* (*)(Node*, void*))trans_lateral_vars_mutator, lateral_vars);
|
||||
}
|
||||
|
||||
/*
|
||||
function name: trans_lateral_vars
|
||||
description: This function performs the transformation of lateral references within a given subquery. It recursively traverses the expression tree using the trans_lateral_vars_mutator function to convert internal Var nodes into subquery forms and external Var nodes into Param nodes.
|
||||
arguments:
|
||||
- `subquery`: The subquery in which lateral references are to be transformed.
|
||||
- `rti`: The index of the subquery in the RangeTblEntry array.
|
||||
- `qual`: The restriction condition expression to be transformed.
|
||||
- `levelsup`: The number of levels up in which the transformation occurs within the subquery.
|
||||
return value: The transformed restriction condition expression.
|
||||
note: The main process is as follows:
|
||||
-> Create a trans_lateral_vars_t structure containing information such as subquery, target_list, rti, and levelsup.
|
||||
-> Recursively traverse the restriction condition expression using the query_or_expression_tree_mutator function, applying the trans_lateral_vars_mutator function for the conversion.
|
||||
date: 2023/8/13
|
||||
contact tel: 18720816902
|
||||
*/
|
||||
static Node* trans_lateral_vars(Query *subquery, Index rti, Node *qual, int levelsup)
|
||||
{
|
||||
trans_lateral_vars_t lateral_vars;
|
||||
|
|
|
|||
Loading…
Reference in New Issue