mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
pgindent run over code.
This commit is contained in:
@ -15,89 +15,90 @@
|
||||
|
||||
/*
|
||||
* Node_Copy
|
||||
* a macro to simplify calling of copyObject on the specified field
|
||||
* a macro to simplify calling of copyObject on the specified field
|
||||
*/
|
||||
#define Node_Copy(from, newnode, field) newnode->field = copyObject(from->field)
|
||||
|
||||
bool _use_keyset_query_optimizer = FALSE;
|
||||
bool _use_keyset_query_optimizer = FALSE;
|
||||
|
||||
static int inspectOpNode(Expr *expr);
|
||||
static int inspectAndNode(Expr *expr);
|
||||
static int inspectOrNode(Expr *expr);
|
||||
static int TotalExpr;
|
||||
static int inspectOpNode(Expr *expr);
|
||||
static int inspectAndNode(Expr *expr);
|
||||
static int inspectOrNode(Expr *expr);
|
||||
static int TotalExpr;
|
||||
|
||||
/**********************************************************************
|
||||
* This routine transforms query trees with the following form:
|
||||
* SELECT a,b, ... FROM one_table WHERE
|
||||
* (v1 = const1 AND v2 = const2 [ vn = constn ]) OR
|
||||
* (v1 = const3 AND v2 = const4 [ vn = constn ]) OR
|
||||
* (v1 = const5 AND v2 = const6 [ vn = constn ]) OR
|
||||
* ...
|
||||
* [(v1 = constn AND v2 = constn [ vn = constn ])]
|
||||
* This routine transforms query trees with the following form:
|
||||
* SELECT a,b, ... FROM one_table WHERE
|
||||
* (v1 = const1 AND v2 = const2 [ vn = constn ]) OR
|
||||
* (v1 = const3 AND v2 = const4 [ vn = constn ]) OR
|
||||
* (v1 = const5 AND v2 = const6 [ vn = constn ]) OR
|
||||
* ...
|
||||
* [(v1 = constn AND v2 = constn [ vn = constn ])]
|
||||
*
|
||||
* into
|
||||
* into
|
||||
*
|
||||
* SELECT a,b, ... FROM one_table WHERE
|
||||
* (v1 = const1 AND v2 = const2 [ vn = constn ]) UNION
|
||||
* SELECT a,b, ... FROM one_table WHERE
|
||||
* (v1 = const3 AND v2 = const4 [ vn = constn ]) UNION
|
||||
* SELECT a,b, ... FROM one_table WHERE
|
||||
* (v1 = const5 AND v2 = const6 [ vn = constn ]) UNION
|
||||
* ...
|
||||
* SELECT a,b, ... FROM one_table WHERE
|
||||
* [(v1 = constn AND v2 = constn [ vn = constn ])]
|
||||
* SELECT a,b, ... FROM one_table WHERE
|
||||
* (v1 = const1 AND v2 = const2 [ vn = constn ]) UNION
|
||||
* SELECT a,b, ... FROM one_table WHERE
|
||||
* (v1 = const3 AND v2 = const4 [ vn = constn ]) UNION
|
||||
* SELECT a,b, ... FROM one_table WHERE
|
||||
* (v1 = const5 AND v2 = const6 [ vn = constn ]) UNION
|
||||
* ...
|
||||
* SELECT a,b, ... FROM one_table WHERE
|
||||
* [(v1 = constn AND v2 = constn [ vn = constn ])]
|
||||
*
|
||||
*
|
||||
* To qualify for transformation the query must not be a sub select,
|
||||
* a HAVING, or a GROUP BY. It must be a single table and have KSQO
|
||||
* set to 'on'.
|
||||
* To qualify for transformation the query must not be a sub select,
|
||||
* a HAVING, or a GROUP BY. It must be a single table and have KSQO
|
||||
* set to 'on'.
|
||||
*
|
||||
* The primary use of this transformation is to avoid the exponrntial
|
||||
* memory consumption of cnfify() and to make use of index access
|
||||
* methods.
|
||||
* The primary use of this transformation is to avoid the exponrntial
|
||||
* memory consumption of cnfify() and to make use of index access
|
||||
* methods.
|
||||
*
|
||||
* daveh@insightdist.com 1998-08-31
|
||||
* daveh@insightdist.com 1998-08-31
|
||||
*
|
||||
* May want to also prune out duplicate terms.
|
||||
* May want to also prune out duplicate terms.
|
||||
**********************************************************************/
|
||||
void
|
||||
transformKeySetQuery(Query *origNode)
|
||||
{
|
||||
/* Qualify as a key set query candidate */
|
||||
if (_use_keyset_query_optimizer == FALSE ||
|
||||
origNode->groupClause ||
|
||||
origNode->havingQual ||
|
||||
origNode->hasAggs ||
|
||||
origNode->utilityStmt ||
|
||||
origNode->unionClause ||
|
||||
origNode->unionall ||
|
||||
origNode->hasSubLinks ||
|
||||
origNode->commandType != CMD_SELECT)
|
||||
/* Qualify as a key set query candidate */
|
||||
if (_use_keyset_query_optimizer == FALSE ||
|
||||
origNode->groupClause ||
|
||||
origNode->havingQual ||
|
||||
origNode->hasAggs ||
|
||||
origNode->utilityStmt ||
|
||||
origNode->unionClause ||
|
||||
origNode->unionall ||
|
||||
origNode->hasSubLinks ||
|
||||
origNode->commandType != CMD_SELECT)
|
||||
return;
|
||||
|
||||
/* Qualify single table query */
|
||||
/* Qualify single table query */
|
||||
if (length(origNode->rtable) != 1)
|
||||
return;
|
||||
|
||||
/* Sorry about the global, not worth passing around */
|
||||
/* 9 expressions seems like a good number. More than 9 */
|
||||
/* and it starts to slow down quite a bit */
|
||||
TotalExpr = 0;
|
||||
/*************************/
|
||||
/* Qualify where clause */
|
||||
/*************************/
|
||||
if ( ! inspectOrNode((Expr*)origNode->qual) || TotalExpr < 9)
|
||||
return;
|
||||
|
||||
/* Copy essential elements into a union node */
|
||||
while (((Expr*)origNode->qual)->opType == OR_EXPR) {
|
||||
/* Sorry about the global, not worth passing around */
|
||||
/* 9 expressions seems like a good number. More than 9 */
|
||||
/* and it starts to slow down quite a bit */
|
||||
TotalExpr = 0;
|
||||
/*************************/
|
||||
/* Qualify where clause */
|
||||
/*************************/
|
||||
if (!inspectOrNode((Expr *) origNode->qual) || TotalExpr < 9)
|
||||
return;
|
||||
|
||||
/* Copy essential elements into a union node */
|
||||
while (((Expr *) origNode->qual)->opType == OR_EXPR)
|
||||
{
|
||||
Query *unionNode = makeNode(Query);
|
||||
|
||||
/* Pull up Expr = */
|
||||
unionNode->qual = lsecond(((Expr*)origNode->qual)->args);
|
||||
/* Pull up Expr = */
|
||||
unionNode->qual = lsecond(((Expr *) origNode->qual)->args);
|
||||
|
||||
/* Pull up balance of tree */
|
||||
origNode->qual = lfirst(((Expr*)origNode->qual)->args);
|
||||
/* Pull up balance of tree */
|
||||
origNode->qual = lfirst(((Expr *) origNode->qual)->args);
|
||||
|
||||
unionNode->commandType = origNode->commandType;
|
||||
unionNode->resultRelation = origNode->resultRelation;
|
||||
@ -121,37 +122,38 @@ transformKeySetQuery(Query *origNode)
|
||||
|
||||
static int
|
||||
/**********************************************************************
|
||||
* Checks for 1 or more OR terms w/ 1 or more AND terms.
|
||||
* AND terms must be equal in size.
|
||||
* Returns the number of each AND term.
|
||||
* Checks for 1 or more OR terms w/ 1 or more AND terms.
|
||||
* AND terms must be equal in size.
|
||||
* Returns the number of each AND term.
|
||||
**********************************************************************/
|
||||
inspectOrNode(Expr *expr)
|
||||
{
|
||||
int rc;
|
||||
Expr *firstExpr, *secondExpr;
|
||||
int rc;
|
||||
Expr *firstExpr,
|
||||
*secondExpr;
|
||||
|
||||
if ( ! (expr && nodeTag(expr) == T_Expr && expr->opType == OR_EXPR))
|
||||
if (!(expr && nodeTag(expr) == T_Expr && expr->opType == OR_EXPR))
|
||||
return 0;
|
||||
|
||||
firstExpr = lfirst(expr->args);
|
||||
secondExpr = lsecond(expr->args);
|
||||
if (nodeTag(firstExpr) != T_Expr || nodeTag(secondExpr) != T_Expr)
|
||||
if (nodeTag(firstExpr) != T_Expr || nodeTag(secondExpr) != T_Expr)
|
||||
return 0;
|
||||
|
||||
if (firstExpr->opType == OR_EXPR && secondExpr->opType == AND_EXPR)
|
||||
{
|
||||
if ((rc = inspectOrNode(firstExpr)) == 0)
|
||||
if ((rc = inspectOrNode(firstExpr)) == 0)
|
||||
return 0;
|
||||
|
||||
return (rc == inspectAndNode(secondExpr)) ? rc : 0;
|
||||
return (rc == inspectAndNode(secondExpr)) ? rc : 0;
|
||||
}
|
||||
else if (firstExpr->opType == AND_EXPR && secondExpr->opType == AND_EXPR)
|
||||
{
|
||||
if ((rc = inspectAndNode(firstExpr)) == 0)
|
||||
if ((rc = inspectAndNode(firstExpr)) == 0)
|
||||
return 0;
|
||||
|
||||
return (rc == inspectAndNode(secondExpr)) ? rc : 0;
|
||||
|
||||
|
||||
return (rc == inspectAndNode(secondExpr)) ? rc : 0;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -160,34 +162,33 @@ inspectOrNode(Expr *expr)
|
||||
|
||||
static int
|
||||
/**********************************************************************
|
||||
* Check for one or more AND terms. Each sub-term must be a T_Const
|
||||
* T_Var expression.
|
||||
* Returns the number of AND terms.
|
||||
* Check for one or more AND terms. Each sub-term must be a T_Const
|
||||
* T_Var expression.
|
||||
* Returns the number of AND terms.
|
||||
**********************************************************************/
|
||||
inspectAndNode(Expr *expr)
|
||||
{
|
||||
int rc;
|
||||
Expr *firstExpr, *secondExpr;
|
||||
int rc;
|
||||
Expr *firstExpr,
|
||||
*secondExpr;
|
||||
|
||||
if ( ! (expr && nodeTag(expr) == T_Expr && expr->opType == AND_EXPR))
|
||||
if (!(expr && nodeTag(expr) == T_Expr && expr->opType == AND_EXPR))
|
||||
return 0;
|
||||
|
||||
firstExpr = lfirst(expr->args);
|
||||
secondExpr = lsecond(expr->args);
|
||||
if (nodeTag(firstExpr) != T_Expr || nodeTag(secondExpr) != T_Expr)
|
||||
if (nodeTag(firstExpr) != T_Expr || nodeTag(secondExpr) != T_Expr)
|
||||
return 0;
|
||||
|
||||
if (firstExpr->opType == AND_EXPR &&
|
||||
secondExpr->opType == OP_EXPR && inspectOpNode(secondExpr))
|
||||
secondExpr->opType == OP_EXPR && inspectOpNode(secondExpr))
|
||||
{
|
||||
rc = inspectAndNode(firstExpr);
|
||||
return ((rc) ? (rc + 1) : 0); /* Add up the AND nodes */
|
||||
rc = inspectAndNode(firstExpr);
|
||||
return ((rc) ? (rc + 1) : 0); /* Add up the AND nodes */
|
||||
}
|
||||
else if (firstExpr->opType == OP_EXPR && inspectOpNode(firstExpr) &&
|
||||
secondExpr->opType == OP_EXPR && inspectOpNode(secondExpr))
|
||||
{
|
||||
else if (firstExpr->opType == OP_EXPR && inspectOpNode(firstExpr) &&
|
||||
secondExpr->opType == OP_EXPR && inspectOpNode(secondExpr))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -195,12 +196,13 @@ inspectAndNode(Expr *expr)
|
||||
|
||||
static int
|
||||
/******************************************************************
|
||||
* Return TRUE if T_Var = T_Const, else FALSE
|
||||
* Actually it does not test for =. Need to do this!
|
||||
* Return TRUE if T_Var = T_Const, else FALSE
|
||||
* Actually it does not test for =. Need to do this!
|
||||
******************************************************************/
|
||||
inspectOpNode(Expr *expr)
|
||||
{
|
||||
Expr *firstExpr, *secondExpr;
|
||||
Expr *firstExpr,
|
||||
*secondExpr;
|
||||
|
||||
if (nodeTag(expr) != T_Expr || expr->opType != OP_EXPR)
|
||||
return FALSE;
|
||||
@ -209,5 +211,5 @@ inspectOpNode(Expr *expr)
|
||||
|
||||
firstExpr = lfirst(expr->args);
|
||||
secondExpr = lsecond(expr->args);
|
||||
return (firstExpr && secondExpr && nodeTag(firstExpr) == T_Var && nodeTag(secondExpr) == T_Const);
|
||||
return (firstExpr && secondExpr && nodeTag(firstExpr) == T_Var && nodeTag(secondExpr) == T_Const);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepqual.c,v 1.14 1999/02/15 01:06:59 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepqual.c,v 1.15 1999/05/25 16:09:45 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -106,8 +106,9 @@ find_nots(Expr *qual)
|
||||
|
||||
if (is_opclause((Node *) qual))
|
||||
{
|
||||
Expr *left = (Expr *) get_leftop(qual);
|
||||
Expr *right = (Expr *) get_rightop(qual);
|
||||
Expr *left = (Expr *) get_leftop(qual);
|
||||
Expr *right = (Expr *) get_rightop(qual);
|
||||
|
||||
if (right)
|
||||
return make_clause(qual->opType, qual->oper,
|
||||
lcons(find_nots(left),
|
||||
@ -162,8 +163,9 @@ normalize(Expr *qual)
|
||||
|
||||
if (is_opclause((Node *) qual))
|
||||
{
|
||||
Expr *left = (Expr *) get_leftop(qual);
|
||||
Expr *right = (Expr *) get_rightop(qual);
|
||||
Expr *left = (Expr *) get_leftop(qual);
|
||||
Expr *right = (Expr *) get_rightop(qual);
|
||||
|
||||
if (right)
|
||||
return make_clause(qual->opType, qual->oper,
|
||||
lcons(normalize(left),
|
||||
@ -229,8 +231,9 @@ qual_cleanup(Expr *qual)
|
||||
|
||||
if (is_opclause((Node *) qual))
|
||||
{
|
||||
Expr *left = (Expr *) get_leftop(qual);
|
||||
Expr *right = (Expr *) get_rightop(qual);
|
||||
Expr *left = (Expr *) get_leftop(qual);
|
||||
Expr *right = (Expr *) get_rightop(qual);
|
||||
|
||||
if (right)
|
||||
return (List *) make_clause(qual->opType, qual->oper,
|
||||
lcons(qual_cleanup(left),
|
||||
@ -295,8 +298,9 @@ pull_args(Expr *qual)
|
||||
|
||||
if (is_opclause((Node *) qual))
|
||||
{
|
||||
Expr *left = (Expr *) get_leftop(qual);
|
||||
Expr *right = (Expr *) get_rightop(qual);
|
||||
Expr *left = (Expr *) get_leftop(qual);
|
||||
Expr *right = (Expr *) get_rightop(qual);
|
||||
|
||||
if (right)
|
||||
return make_clause(qual->opType, qual->oper,
|
||||
lcons(pull_args(left),
|
||||
@ -485,7 +489,7 @@ or_normalize(List *orlist)
|
||||
{
|
||||
return (or_normalize(lcons(distribute_args(lfirst(new_orlist),
|
||||
((Expr *) distributable)->args),
|
||||
lnext(new_orlist))));
|
||||
lnext(new_orlist))));
|
||||
}
|
||||
else
|
||||
return orlist;
|
||||
@ -537,8 +541,9 @@ remove_ands(Expr *qual)
|
||||
return NIL;
|
||||
if (is_opclause((Node *) qual))
|
||||
{
|
||||
Expr *left = (Expr *) get_leftop(qual);
|
||||
Expr *right = (Expr *) get_rightop(qual);
|
||||
Expr *left = (Expr *) get_leftop(qual);
|
||||
Expr *right = (Expr *) get_rightop(qual);
|
||||
|
||||
if (right)
|
||||
return (List *) make_clause(qual->opType, qual->oper,
|
||||
lcons(remove_ands(left),
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.20 1999/05/17 17:03:18 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.21 1999/05/25 16:09:46 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -211,8 +211,8 @@ replace_matching_resname(List *new_tlist, List *old_tlist)
|
||||
* locks.
|
||||
*
|
||||
* So, copy all these entries to the end of the target list and set their
|
||||
* 'resjunk' value to true to show that these are special attributes and
|
||||
* have to be treated specially by the executor!
|
||||
* 'resjunk' value to true to show that these are special attributes
|
||||
* and have to be treated specially by the executor!
|
||||
*/
|
||||
foreach(temp, old_tlist)
|
||||
{
|
||||
@ -231,28 +231,27 @@ replace_matching_resname(List *new_tlist, List *old_tlist)
|
||||
}
|
||||
|
||||
/*
|
||||
* Also it is possible that the parser or rewriter added
|
||||
* some junk attributes to hold GROUP BY expressions which
|
||||
* are not part of the result attributes.
|
||||
* We can simply identify them by looking at the resgroupref
|
||||
* in the TLE's resdom, which is a unique number telling which
|
||||
* TLE belongs to which GroupClause.
|
||||
* Also it is possible that the parser or rewriter added some junk
|
||||
* attributes to hold GROUP BY expressions which are not part of
|
||||
* the result attributes. We can simply identify them by looking
|
||||
* at the resgroupref in the TLE's resdom, which is a unique
|
||||
* number telling which TLE belongs to which GroupClause.
|
||||
*/
|
||||
if (old_tle->resdom->resgroupref > 0)
|
||||
{
|
||||
bool already_there = FALSE;
|
||||
TargetEntry *new_tle;
|
||||
Resdom *newresno;
|
||||
bool already_there = FALSE;
|
||||
TargetEntry *new_tle;
|
||||
Resdom *newresno;
|
||||
|
||||
/*
|
||||
* Check if the tle is already in the new list
|
||||
*/
|
||||
foreach(i, t_list)
|
||||
{
|
||||
new_tle = (TargetEntry *)lfirst(i);
|
||||
new_tle = (TargetEntry *) lfirst(i);
|
||||
|
||||
if (new_tle->resdom->resgroupref ==
|
||||
old_tle->resdom->resgroupref)
|
||||
if (new_tle->resdom->resgroupref ==
|
||||
old_tle->resdom->resgroupref)
|
||||
{
|
||||
already_there = TRUE;
|
||||
break;
|
||||
@ -349,8 +348,8 @@ new_relation_targetlist(Oid relid, Index rt_index, NodeTag node_type)
|
||||
TargetEntry *temp_list = NULL;
|
||||
|
||||
temp_var = makeVar(rt_index, attno, atttype,
|
||||
get_atttypmod(relid, attno),
|
||||
0, rt_index, attno);
|
||||
get_atttypmod(relid, attno),
|
||||
0, rt_index, attno);
|
||||
|
||||
temp_list = makeTargetEntry(makeResdom(attno,
|
||||
atttype,
|
||||
|
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.30 1999/02/18 00:49:32 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.31 1999/05/25 16:09:47 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -223,8 +223,8 @@ plan_inherit_queries(Query *parse, Index rt_index)
|
||||
List *union_relids = NIL;
|
||||
|
||||
union_relids = find_all_inheritors(lconsi(rt_entry->relid,
|
||||
NIL),
|
||||
NIL);
|
||||
NIL),
|
||||
NIL);
|
||||
|
||||
/*
|
||||
* Remove the flag for this relation, since we're about to handle it
|
||||
|
Reference in New Issue
Block a user