为src/common/backend/parser下的文件添加了部分注释 #29
|
|
@ -2124,7 +2124,7 @@ static void reduce_orderby_recurse(Query* query, Node* jtnode, bool reduce);
|
|||
|
||||
/*
|
||||
* reduce_orderby_recurse() ---
|
||||
* Recurse in a jointree or a setop tree to reduce orderby clause in it.
|
||||
* Recurse in a jointree or a setop tree and try to reduce NULL orderby-clause.
|
||||
*
|
||||
* @ Caller: reduce_orderby()
|
||||
*
|
||||
|
|
@ -2137,7 +2137,7 @@ static void reduce_orderby_recurse(Query* query, Node* jtnode, bool reduce);
|
|||
*
|
||||
* Note: this routine is the main recursive procedure through the orderby reducing
|
||||
* process. It will recursively traverses a jointree or a setop tree in an attempt
|
||||
* to reduce sortClauses for it.
|
||||
* to drop NULL-returns orderby for it.
|
||||
*/
|
||||
static void reduce_orderby_recurse(Query* query, Node* jtnode, bool reduce)
|
||||
{
|
||||
|
|
@ -2170,14 +2170,19 @@ static void reduce_orderby_recurse(Query* query, Node* jtnode, bool reduce)
|
|||
ListCell* l = NULL;
|
||||
bool flag = false;
|
||||
|
||||
|
||||
/* If length of fromlist > 1, then certainly we can reduce the sort times. */
|
||||
/*
|
||||
* If the number of tables referenced by the from statement is 1, then there are two
|
||||
* situations: If the from-clause is at the top of the query, we do not need to drop
|
||||
* its orderby, even if the orderby-clause returns NULL; Otherwise, it indicates that
|
||||
* the query refers to more than one table, at which point we can try to drop the
|
||||
* orderby-clause of the only table referenced by the current from-clause.
|
||||
*/
|
||||
if (1 == list_length(f->fromlist))
|
||||
flag = reduce;
|
||||
else
|
||||
flag = true;
|
||||
|
||||
/* Recurse into each reference of query to reduce its sortClauses. */
|
||||
/* Recurse into each reference of query to reduce its NULL orderby. */
|
||||
foreach (l, f->fromlist)
|
||||
reduce_orderby_recurse(query, (Node*)lfirst(l), flag);
|
||||
} else if (IsA(jtnode, JoinExpr)) {
|
||||
|
|
@ -2211,7 +2216,7 @@ static void reduce_orderby_recurse(Query* query, Node* jtnode, bool reduce)
|
|||
|
||||
/*
|
||||
* reduce_orderby_final() ---
|
||||
* Reduce orderby clause for subquery if the subquery has a sortClause.
|
||||
* Reduce orderby clause for subquery if it has a NULL-returns orderby.
|
||||
*
|
||||
* @ Caller: reduce_orderby_recurse()
|
||||
*
|
||||
|
|
@ -2220,12 +2225,17 @@ static void reduce_orderby_recurse(Query* query, Node* jtnode, bool reduce)
|
|||
* process that decide whether to reduce the orderby clause for subquery.
|
||||
* @ Returns: void
|
||||
*
|
||||
* Note: if the subquery has a sortClause and the passed-in parameter reduce
|
||||
* is true, then drop this orderby clause for the subquery.
|
||||
* Note: if the subquery has NULL-returns orderby and the passed-in parameter
|
||||
* reduce is true, drop this orderby clause for the subquery.
|
||||
*/
|
||||
static void reduce_orderby_final(RangeTblEntry* rte, bool reduce)
|
||||
{
|
||||
/* Drop the orderby clause for subquery if reduce is true. */
|
||||
|
||||
/*
|
||||
* Both subquery's limitOffset and limitCount are zero, which shows
|
||||
* that this orderby actually doesn't return any item as the result
|
||||
* of a query or used in join operation.
|
||||
*/
|
||||
if (rte->rtekind == RTE_SUBQUERY) {
|
||||
if (reduce && rte->subquery->sortClause && !rte->subquery->limitOffset && !rte->subquery->limitCount) {
|
||||
pfree_ext(rte->subquery->sortClause);
|
||||
|
|
@ -2287,7 +2297,7 @@ void reduce_orderby(Query* query, bool reduce)
|
|||
|
||||
/*
|
||||
* Recurse to find subquerys in FROM, JOIN or subqueries, and to decide
|
||||
* whether to reduce orderby or not.
|
||||
* whether to drop its orderby or not.
|
||||
*/
|
||||
reduce_orderby_recurse(query, (Node*)query->jointree, reduce);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue