提交 0da1de0e 编写于 作者: H Heikki Linnakangas

Misc cosmetic cleanup.

These changes were lifted from upcoming PostgreSQL 8.3 merge branch, but
are not related to the merge per se, so let's get them out of the way
before the big merge lands. Plus other cosmetic things in neighbouring
code that stuck my eye.
上级 8f83a5c7
......@@ -714,9 +714,8 @@ bool isGreenplumDbHashable(Oid typid)
/* we can hash all arrays */
if (typeIsArrayType(typid))
return true;
/*
* if this type is a domain type, get its base type.
*/
/* if this type is a domain type, get its base type */
if (get_typtype(typid) == 'd')
typid = getBaseType(typid);
......@@ -916,6 +915,5 @@ ignoreblanks(char *data, int len)
static int
ispowof2(int numsegs)
{
return !(numsegs & (numsegs - 1));
}
......@@ -290,7 +290,7 @@ cdbparallelize(PlannerInfo *root,
* The plan and query arguments should not be null.
* ----------------------------------------------------------------------- *
*/
void
static void
prescan(Plan *plan, PlanProfile * context)
{
if ( prescan_walker((Node *) plan, context) )
......@@ -334,7 +334,8 @@ static Node *ParallelizeCorrelatedSubPlanUpdateFlowMutator(Node *node);
/**
* Does an expression contain a parameter?
*/
static bool ContainsParamWalker(Node *expr, void *ctx)
static bool
ContainsParamWalker(Node *expr, void *ctx)
{
Assert(ctx == NULL);
......@@ -354,7 +355,8 @@ static bool ContainsParamWalker(Node *expr, void *ctx)
* Replaces all vars in an expression with OUTER vars referring to the
* targetlist contained in the context (ctx->outerTL).
*/
static Node* MapVarsMutator(Node *expr, MapVarsMutatorContext *ctx)
static Node *
MapVarsMutator(Node *expr, MapVarsMutatorContext *ctx)
{
Assert(ctx);
......@@ -381,7 +383,8 @@ static Node* MapVarsMutator(Node *expr, MapVarsMutatorContext *ctx)
/**
* Add a materialize node to prevent rescan of subplan.
*/
Plan *materialize_subplan(PlannerInfo *root, Plan *subplan)
static Plan *
materialize_subplan(PlannerInfo *root, Plan *subplan)
{
Plan *mat = materialize_finished_plan(root, subplan);
((Material *)mat)->cdb_strict = true;
......@@ -399,7 +402,8 @@ Plan *materialize_subplan(PlannerInfo *root, Plan *subplan)
* Not listing every node type here, if further bug found due to not updating flow
* after cdbparallelize, just simply add that node type here.
* */
static Node *ParallelizeCorrelatedSubPlanUpdateFlowMutator(Node *node)
static Node *
ParallelizeCorrelatedSubPlanUpdateFlowMutator(Node *node)
{
Assert(is_plan_node(node));
switch (nodeTag(node))
......@@ -454,7 +458,8 @@ static Node *ParallelizeCorrelatedSubPlanUpdateFlowMutator(Node *node)
* refer to the outer parameter, but the planner isn't currently smart enough to
* distinguish that, so we just disable index scans altogether in a subplan.
*/
static Node* ParallelizeCorrelatedSubPlanMutator(Node *node, ParallelizeCorrelatedPlanWalkerContext *ctx)
static Node *
ParallelizeCorrelatedSubPlanMutator(Node *node, ParallelizeCorrelatedPlanWalkerContext *ctx)
{
if (node == NULL)
return NULL;
......@@ -671,7 +676,8 @@ static Node* ParallelizeCorrelatedSubPlanMutator(Node *node, ParallelizeCorrelat
/**
* Parallelizes a correlated subplan. See ParallelizeCorrelatedSubPlanMutator for details.
*/
Plan* ParallelizeCorrelatedSubPlan(PlannerInfo *root, SubPlan *spExpr, Plan *plan, Movement m, bool subPlanDistributed)
Plan *
ParallelizeCorrelatedSubPlan(PlannerInfo *root, SubPlan *spExpr, Plan *plan, Movement m, bool subPlanDistributed)
{
ParallelizeCorrelatedPlanWalkerContext ctx;
ctx.base.node = (Node *) root;
......@@ -693,7 +699,8 @@ Plan* ParallelizeCorrelatedSubPlan(PlannerInfo *root, SubPlan *spExpr, Plan *pla
* - If the subplan is correlated, then it transforms the correlated into a form that is
* executable
*/
void ParallelizeSubplan(SubPlan *spExpr, PlanProfile *context)
void
ParallelizeSubplan(SubPlan *spExpr, PlanProfile *context)
{
Assert(!spExpr->is_parallelized);
......@@ -794,7 +801,7 @@ void ParallelizeSubplan(SubPlan *spExpr, PlanProfile *context)
* As in the case of the main plan, the actual Motion node is
* attached later.
*/
bool
static bool
prescan_walker(Node *node, PlanProfile * context)
{
if (node == NULL)
......@@ -1076,30 +1083,26 @@ broadcastPlan(Plan *plan, bool stable, bool rescannable)
* This method is used to determine if motion nodes may be avoided for certain insert-select
* statements. To do this it determines if the loci are compatible (ignoring relabeling).
*/
static bool loci_compatible(List *hashExpr1, List *hashExpr2)
static bool
loci_compatible(List *hashExpr1, List *hashExpr2)
{
ListCell *cell1 = NULL;
ListCell *cell2 = NULL;
ListCell *cell1;
ListCell *cell2;
if (list_length(hashExpr1) != list_length(hashExpr2))
{
return false;
}
forboth (cell1, hashExpr1, cell2, hashExpr2) {
Expr *var1;
Expr *var2;
var1 = (Expr *) lfirst(cell1);
var2 = (Expr *) lfirst(cell2);
forboth (cell1, hashExpr1, cell2, hashExpr2)
{
Expr *var1 = (Expr *) lfirst(cell1);
Expr *var2 = (Expr *) lfirst(cell2);
/* right side variable may be encapsulated by a relabel node. motion, however, does not care about relabel nodes. */
if (IsA(var2, RelabelType))
var2 = ((RelabelType *)var2)->arg;
if (!equal(var1, var2))
{
return false;
}
}
return true;
}
......@@ -1143,7 +1146,7 @@ repartitionPlan(Plan *plan, bool stable, bool rescannable, List *hashExpr)
* Returns true if successful. Returns false and doesn't change anything
* if the request cannot be honored.
*/
bool
static bool
adjustPlanFlow(Plan *plan,
bool stable,
bool rescannable,
......
......@@ -857,22 +857,16 @@ convert_EXISTS_to_join(PlannerInfo *root, List** rtrlist_inout, SubLink *sublink
Assert(IsA(subselect, Query));
if (subselect->jointree->fromlist == NULL)
{
return (Node *) sublink;
}
if (has_correlation_in_funcexpr_rte(subselect->rtable))
{
return (Node *) sublink;
}
/**
/*
* If deeply correlated, don't bother.
*/
if (IsSubqueryMultiLevelCorrelated(subselect))
{
return (Node *) sublink;
}
/*
* 'LIMIT n' makes EXISTS false when n <= 0, and doesn't affect the outcome
......@@ -933,7 +927,8 @@ convert_EXISTS_to_join(PlannerInfo *root, List** rtrlist_inout, SubLink *sublink
subselect->sortClause = NIL;
subselect->distinctClause = NIL;
/* HAVING is the only place that could still contain aggregates.
/*
* HAVING is the only place that could still contain aggregates.
* We can delete targetlist if there is no havingQual.
*/
if (subselect->havingQual == NULL)
......@@ -967,34 +962,34 @@ convert_EXISTS_to_join(PlannerInfo *root, List** rtrlist_inout, SubLink *sublink
return make_and_qual(limitqual, (Node *)sublink);
}
/*
* Build subquery RTE, InClauseInfo, etc.
*/
/*
* Build subquery RTE, InClauseInfo, etc.
*/
/* Build an InClauseInfo struct. */
/* Build an InClauseInfo struct. */
ininfo = makeNode(InClauseInfo);
ininfo->sub_targetlist = NULL;
ininfo->sub_targetlist = NULL;
/* Determine the index of the subquery RTE that we'll create below. */
/* Determine the index of the subquery RTE that we'll create below. */
rtindex = list_length(root->parse->rtable) + 1;
ininfo->righthand = bms_make_singleton(rtindex);
/* Tell join planner to quell duplication of outer query result rows. */
/* Tell join planner to quell duplication of outer query result rows. */
root->in_info_list = lappend(root->in_info_list, ininfo);
/* Make a subquery RTE in the current query level. */
rte = addRangeTableEntryForSubquery(NULL,
/* Make a subquery RTE in the current query level. */
rte = addRangeTableEntryForSubquery(NULL,
subselect,
makeAlias("EXISTS_subquery", NIL),
false);
root->parse->rtable = lappend(root->parse->rtable, rte);
/* Tell caller to augment the jointree with a reference to the new RTE. */
rtr = makeNode(RangeTblRef);
/* Tell caller to augment the jointree with a reference to the new RTE. */
rtr = makeNode(RangeTblRef);
rtr->rtindex = rtindex;
*rtrlist_inout = lappend(*rtrlist_inout, rtr);
*rtrlist_inout = lappend(*rtrlist_inout, rtr);
return limitqual;
return limitqual;
} /* convert_EXISTS_to_join */
......@@ -1284,18 +1279,18 @@ make_lasj_quals(PlannerInfo *root, SubLink * sublink, int subquery_indx)
Assert(sublink->subLinkType == ALL_SUBLINK);
join_pred = (Expr *) convert_testexpr(root,
sublink->testexpr,
subquery_indx,
&subtlist);
sublink->testexpr,
subquery_indx,
&subtlist);
join_pred = canonicalize_qual(make_notclause(join_pred));
Assert(join_pred != NULL);
return (Node *) join_pred;
}
/* add IS NOT FALSE clause on top of the clause */
Node *
static Node *
add_null_match_clause(Node *clause)
{
BooleanTest *btest;
......@@ -1312,11 +1307,14 @@ add_null_match_clause(Node *clause)
* Given an expression tree, extract all inner vars and construct a qual that eliminates NULLs.
* E.g. For input (i1 = o1) and (i2 = o1 + 2), the function produces NOT NULL (i1) and NOT NULL (i2)
*/
static Node* not_null_inner_vars(Node *clause)
static Node *
not_null_inner_vars(Node *clause)
{
List *allVars = extract_nodes(NULL /* PlannerGlobal */, clause, T_Var);
List *notNullClauses = NULL;
ListCell *lc = NULL;
List *allVars;
List *notNullClauses = NIL;
ListCell *lc;
allVars = extract_nodes(NULL /* PlannerGlobal */, clause, T_Var);
foreach (lc, allVars)
{
Assert(IsA(lfirst(lc), Var));
......@@ -1331,13 +1329,9 @@ static Node* not_null_inner_vars(Node *clause)
}
if (notNullClauses)
{
return (Node *) make_andclause(notNullClauses);
}
else
{
return NULL;
}
}
......@@ -1816,7 +1810,8 @@ has_correlation_in_funcexpr_rte(List *rtable)
{
/* check if correlation occurs in a func expr in the from clause of the
subselect */
ListCell *lc_rte = NULL;
ListCell *lc_rte;
foreach(lc_rte, rtable)
{
RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc_rte);
......
......@@ -201,56 +201,55 @@ static void
ExplainDXL(Query *query, ExplainStmt *stmt, const char *queryString,
ParamListInfo params, TupOutputState *tstate)
{
MemoryContext oldcxt = CurrentMemoryContext;
ExplainState explainState;
ExplainState *es = &explainState;
MemoryContext oldcxt = CurrentMemoryContext;
ExplainState explainState;
ExplainState *es = &explainState;
StringInfoData buf;
bool save_enumerate;
/* Initialize ExplainState structure. */
memset(es, 0, sizeof(*es));
es->showstatctx = NULL;
es->deferredError = NULL;
es->pstmt = NULL;
/* Initialize ExplainState structure. */
memset(es, 0, sizeof(*es));
es->showstatctx = NULL;
es->deferredError = NULL;
es->pstmt = NULL;
initStringInfo(&buf);
bool enumerate = optimizer_enumerate_plans;
save_enumerate = optimizer_enumerate_plans;
/* Do the EXPLAIN. */
PG_TRY();
{
// enable plan enumeration before calling optimizer
optimizer_enumerate_plans = true;
/* Do the EXPLAIN. */
PG_TRY();
{
// enable plan enumeration before calling optimizer
optimizer_enumerate_plans = true;
// optimize query using optimizer and get generated plan in DXL format
char *dxl = SzDXLPlan(query);
// optimize query using optimizer and get generated plan in DXL format
char *dxl = SzDXLPlan(query);
// restore old value of enumerate plans GUC
optimizer_enumerate_plans = enumerate;
// restore old value of enumerate plans GUC
optimizer_enumerate_plans = save_enumerate;
if (NULL == dxl)
{
elog(NOTICE, "Optimizer failed to produce plan");
}
else
{
if (dxl == NULL)
elog(NOTICE, "Optimizer failed to produce plan");
else
{
do_text_output_multiline(tstate, dxl);
do_text_output_oneline(tstate, ""); /* separator line */
pfree(dxl);
}
}
/* Free the memory we used. */
MemoryContextSwitchTo(oldcxt);
}
PG_CATCH();
{
// restore old value of enumerate plans GUC
optimizer_enumerate_plans = enumerate;
/* Free the memory we used. */
MemoryContextSwitchTo(oldcxt);
}
PG_CATCH();
{
// restore old value of enumerate plans GUC
optimizer_enumerate_plans = save_enumerate;
/* Exit to next error handler. */
PG_RE_THROW();
}
PG_END_TRY();
/* Exit to next error handler. */
PG_RE_THROW();
}
PG_END_TRY();
}
#endif
......
......@@ -1296,7 +1296,7 @@ DefinePartitionedRelation(CreateStmt *stmt, Oid relOid)
ProcessUtility((Node *)(((Query *)pUtl)->utilityStmt),
synthetic_sql,
NULL,
NULL,
false, /* not top level */
dest,
NULL);
......@@ -1338,7 +1338,7 @@ EvaluateDeferredStatements(List *deferredStmts)
uquery = (Query*)utilityStmt;
Insist(uquery->commandType == CMD_UTILITY);
ereport(DEBUG1,
ereport(DEBUG1,
(errmsg("processing deferred utility statement")));
ProcessUtility((Node*)uquery->utilityStmt,
......@@ -6532,7 +6532,7 @@ find_composite_type_dependencies(Oid typeOid,
{
cqContext *pcqCtx;
HeapTuple depTup;
Oid arrayOid;
Oid arrayOid;
/*
* We scan pg_depend to find those things that depend on the rowtype. (We
......@@ -7946,11 +7946,11 @@ ATExecAddIndex(AlteredTableInfo *tab, Relation rel,
heap_close(crel, AccessShareLock); /* already locked master */
ProcessUtility((Node *)ats,
ProcessUtility((Node *)ats,
synthetic_sql,
NULL,
NULL,
false, /* not top level */
dest,
dest,
NULL);
}
}
......@@ -8695,7 +8695,7 @@ transformFkeyCheckAttrs(Relation pkrel,
caql_endscan(pcqCtx);
if (found)
break;
} /* end foreach(indexoidscan, indexoidlist) */
}
if (!found)
ereport(ERROR,
......@@ -10405,19 +10405,12 @@ ATExecSetRelOptions(Relation rel, List *defList, bool isReset)
static void
copy_append_only_data(
RelFileNode *oldRelFileNode,
RelFileNode *newRelFileNode,
int32 segmentFileNum,
char *relationName,
int64 eof,
ItemPointer persistentTid,
int64 persistentSerialNum,
char *buffer)
{
MIRRORED_LOCK_DECLARE;
......@@ -11220,16 +11213,9 @@ ATExecSetTableSpace(Oid tableOid, Oid newTableSpace, TableOidInfo *oidInfo)
* Copy data, block by block
*/
static void
copy_buffer_pool_data(
Relation rel,
SMgrRelation dst,
ItemPointer persistentTid,
int64 persistentSerialNum,
bool useWal)
copy_buffer_pool_data(Relation rel, SMgrRelation dst,
ItemPointer persistentTid, int64 persistentSerialNum,
bool useWal)
{
SMgrRelation src;
BlockNumber nblocks;
......@@ -12397,11 +12383,11 @@ build_hidden_type(Form_pg_attribute att)
parsetrees = parse_analyze((Node *)newtype, NULL, NULL, 0);
Assert(list_length(parsetrees) == 1);
q = (Query *)linitial(parsetrees);
ProcessUtility((Node *)q->utilityStmt,
ProcessUtility((Node *)q->utilityStmt,
synthetic_sql,
NULL,
NULL,
false, /* not top level */
dest,
dest,
NULL);
CommandCounterIncrement();
......@@ -12412,11 +12398,11 @@ build_hidden_type(Form_pg_attribute att)
inputname = copyObject(linitial(iofunc->funcname));
parsetrees = parse_analyze((Node *)iofunc, NULL, NULL, 0);
q = (Query *)linitial(parsetrees);
ProcessUtility((Node *)q->utilityStmt,
ProcessUtility((Node *)q->utilityStmt,
synthetic_sql,
NULL,
NULL,
false, /* not top level */
dest,
dest,
NULL);
CommandCounterIncrement();
......@@ -12428,9 +12414,9 @@ build_hidden_type(Form_pg_attribute att)
q = (Query *)linitial(parsetrees);
ProcessUtility((Node *)q->utilityStmt,
synthetic_sql,
NULL,
NULL,
false, /* not top level */
dest,
dest,
NULL);
CommandCounterIncrement();
......@@ -12471,9 +12457,9 @@ build_hidden_type(Form_pg_attribute att)
q = (Query *)linitial(parsetrees);
ProcessUtility((Node *)q->utilityStmt,
synthetic_sql,
NULL,
NULL,
false, /* not top level */
dest,
dest,
NULL);
CommandCounterIncrement();
......@@ -12785,11 +12771,11 @@ prebuild_temp_table(Relation rel, RangeVar *tmpname, List *distro, List *opts,
parsetrees = parse_analyze((Node *)cs, NULL, NULL, 0);
Assert(list_length(parsetrees) == 1);
q = (Query *)linitial(parsetrees);
ProcessUtility((Node *)q->utilityStmt,
ProcessUtility((Node *)q->utilityStmt,
synthetic_sql,
NULL,
NULL,
false, /* not top level */
dest,
dest,
NULL);
CommandCounterIncrement();
......@@ -12821,11 +12807,11 @@ prebuild_temp_table(Relation rel, RangeVar *tmpname, List *distro, List *opts,
parsetrees = parse_analyze((Node *)ats, NULL, NULL, 0);
Assert(list_length(parsetrees) == 1);
q = (Query *)linitial(parsetrees);
ProcessUtility((Node *)q->utilityStmt,
ProcessUtility((Node *)q->utilityStmt,
synthetic_sql,
NULL,
NULL,
false, /* not top level */
dest,
dest,
NULL);
CommandCounterIncrement();
}
......@@ -14343,9 +14329,9 @@ ATPExecPartDrop(Relation rel,
ProcessUtility((Node *) ds,
synthetic_sql,
NULL,
NULL,
false, /* not top level */
dest,
dest,
NULL);
/* Notify of name if did not use name for partition id spec */
......@@ -15074,7 +15060,7 @@ ATPExecPartRename(Relation rel,
synthetic_sql,
NULL,
false, /* not top level */
dest,
dest,
NULL);
/* process children if there are any */
......@@ -15095,9 +15081,9 @@ ATPExecPartRename(Relation rel,
ProcessUtility((Node *) renStmt,
synthetic_sql,
NULL,
NULL,
false, /* not top level */
dest,
dest,
NULL);
renamed++;
}
......@@ -16025,7 +16011,7 @@ ATPExecPartSplit(Relation *rel,
synthetic_sql,
NULL,
false, /* not top level */
dest,
dest,
NULL);
CommandCounterIncrement();
......@@ -16069,9 +16055,9 @@ ATPExecPartSplit(Relation *rel,
heap_close(*rel, NoLock);
ProcessUtility((Node *)q->utilityStmt,
synthetic_sql,
NULL,
NULL,
false, /* not top level */
dest,
dest,
NULL);
*rel = heap_open(relid, AccessExclusiveLock);
CommandCounterIncrement();
......@@ -16130,11 +16116,11 @@ ATPExecPartSplit(Relation *rel,
{
q = (Query *)lfirst(lc);
ProcessUtility((Node *)q->utilityStmt,
ProcessUtility((Node *)q->utilityStmt,
synthetic_sql,
NULL,
NULL,
false, /* not top level */
dest,
dest,
NULL);
}
......@@ -16494,11 +16480,11 @@ ATPExecPartSplit(Relation *rel,
q = (Query *)linitial(parsetrees);
heap_close(*rel, NoLock);
ProcessUtility((Node *)q->utilityStmt,
ProcessUtility((Node *)q->utilityStmt,
synthetic_sql,
NULL,
NULL,
false, /* not top level */
dest,
dest,
NULL);
*rel = heap_open(relid, AccessExclusiveLock);
......@@ -16763,9 +16749,9 @@ ATPExecPartTruncate(Relation rel,
ProcessUtility( (Node *) ts,
synthetic_sql,
NULL,
NULL,
false, /* not top level */
dest,
dest,
NULL);
/* Notify of name if did not use name for partition id spec */
......@@ -16893,8 +16879,7 @@ AlterTableNamespace(RangeVar *relation, const char *newschema)
}
static void
AlterRelationNamespaceInternalTwo(Relation rel,
Oid relid,
AlterRelationNamespaceInternalTwo(Relation rel, Oid relid,
Oid oldNspOid, Oid newNspOid,
bool hasDependEntry,
const char *newschema)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册