PostgreSQL code Analysis, query optimization section.
Here the parts of the canonical predicate expression are sorted out, and the order of reading is as follows:
One, PostgreSQL code Analysis, query optimization section, canonicalize_qual
Two, PostgreSQL code Analysis, query Optimization section, Pull_ands () and Pull_ors ()
Third, PostgreSQL Code Analysis, query optimization section, Process_duplicate_ors
*************************************************************************************************************** **********************************************
The code for Pull_ands () and pull_ors () is easier to understand, which is to flatten the and operations of the tree structure, which is the pull_ands example of pull_ors logic:
/*
* pull_ands
* Recursively flatten nested AND clauses into a single and-clause list.
*
* Input is the arglist of an AND clause.
* Returns the rebuilt arglist (note original list structure is not touched).
*/
static List *
pull_ands(List *andlist)
{
List *out_list = NIL;
ListCell *arg;
foreach(arg, andlist)
{
Node *subexpr = (Node *) lfirst(arg);
/*
* Note: we can destructively concat the subexpression's arglist
* because we know the recursive invocation of pull_ands will have
* built a new arglist not shared with any other expr. Otherwise we'd
* need a list_copy here.
*/
if (and_clause(subexpr))
out_list = list_concat(out_list,
pull_ands(((BoolExpr *) subexpr)->args));
else
out_list = lappend(out_list, subexpr);
}
return out_list;
}
/*
* pull_ors
* Recursively flatten nested OR clauses into a single or-clause list.
*
* Input is the arglist of an OR clause.
* Returns the rebuilt arglist (note original list structure is not touched).
*/
static List *
pull_ors(List *orlist)
{
List *out_list = NIL;
ListCell *arg;
foreach(arg, orlist)
{
Node *subexpr = (Node *) lfirst(arg);
/*
* Note: we can destructively concat the subexpression's arglist
* because we know the recursive invocation of pull_ors will have
* built a new arglist not shared with any other expr. Otherwise we'd
* need a list_copy here.
*/
if (or_clause(subexpr))
out_list = list_concat(out_list,
pull_ors(((BoolExpr *) subexpr)->args));
else
out_list = lappend(out_list, subexpr);
}
return out_list;
}
A Blog:http://blog.csdn.net/shujiezhang of understanding
PostgreSQL code Analysis, query Optimization section, Pull_ands () and Pull_ors ()