diff --git a/src/backend/executor/execQual.c b/src/backend/executor/execQual.c index 1c3e53888b2d18beb0dab6b5e1dbe00528c097b0..4889be4d98a6b176fc985d5ecf1e460f895fefed 100644 --- a/src/backend/executor/execQual.c +++ b/src/backend/executor/execQual.c @@ -89,10 +89,10 @@ static Datum ExecEvalScalarVarFast(ExprState *exprstate, ExprContext *econtext, static Datum ExecEvalWholeRowVar(WholeRowVarExprState *wrvstate, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone); -static Datum ExecEvalWholeRowSlow(WholeRowVarExprState *wrvstate, +static Datum ExecEvalWholeRowFast(WholeRowVarExprState *wrvstate, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone); -static Datum ExecEvalWholeRowFast(WholeRowVarExprState *wrvstate, +static Datum ExecEvalWholeRowSlow(WholeRowVarExprState *wrvstate, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone); static Datum ExecEvalConst(ExprState *exprstate, ExprContext *econtext, @@ -156,11 +156,11 @@ static Datum ExecEvalCoalesce(CoalesceExprState *coalesceExpr, static Datum ExecEvalMinMax(MinMaxExprState *minmaxExpr, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone); +static Datum ExecEvalXml(XmlExprState *xmlExpr, ExprContext *econtext, + bool *isNull, ExprDoneCond *isDone); static Datum ExecEvalNullIf(FuncExprState *nullIfExpr, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone); -static Datum ExecEvalXml(XmlExprState *xmlExpr, ExprContext *econtext, - bool *isNull, ExprDoneCond *isDone); static Datum ExecEvalNullTest(NullTestState *nstate, ExprContext *econtext, bool *isNull, ExprDoneCond *isDone); @@ -689,7 +689,6 @@ ExecEvalScalarVar(ExprState *exprstate, ExprContext *econtext, if (isDone) *isDone = ExprSingleResult; - Assert(econtext->ecxt_scantuple != NULL || econtext->ecxt_innertuple != NULL || econtext->ecxt_outertuple != NULL); /* * Get the input slot and attribute number we want * @@ -746,6 +745,7 @@ ExecEvalScalarVar(ExprState *exprstate, ExprContext *econtext, if (attnum > slot_tupdesc->natts) /* should never happen */ elog(ERROR, "attribute number %d exceeds number of columns %d", attnum, slot_tupdesc->natts); + attr = slot_tupdesc->attrs[attnum - 1]; /* can't check type if dropped, since atttypid is probably 0 */ @@ -1159,7 +1159,6 @@ ExecEvalParam(ExprState *exprstate, ExprContext *econtext, ParamExecData *prm; prm = &(econtext->ecxt_param_exec_vals[thisParamId]); - if (prm->execPlan != NULL) { /* Parameter not evaluated yet, so go do it */ @@ -2848,10 +2847,10 @@ static void FastPathScalarArrayOp(ScalarArrayOpExpr *opexpr, ScalarArrayOpExprSt * (for ANY and ALL respectively). Of course we short-circuit as soon as * the result is known. */ - static Datum +static Datum ExecEvalScalarArrayOp(ScalarArrayOpExprState *sstate, - ExprContext *econtext, - bool *isNull, ExprDoneCond *isDone) + ExprContext *econtext, + bool *isNull, ExprDoneCond *isDone) { ScalarArrayOpExpr *opexpr = (ScalarArrayOpExpr *) sstate->fxprstate.xprstate.expr; bool useOr = opexpr->useOr; @@ -2880,7 +2879,7 @@ ExecEvalScalarArrayOp(ScalarArrayOpExprState *sstate, if (sstate->fxprstate.func.fn_oid == InvalidOid) { init_fcache(opexpr->opfuncid, &sstate->fxprstate, - econtext->ecxt_per_query_memory, true); + econtext->ecxt_per_query_memory, true); Assert(!sstate->fxprstate.func.fn_retset); } diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index e36604832f41ac0b661268a89675244def2ac882..fd903c908cadd79c5505a12e70992a67facdb228 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -72,7 +72,8 @@ static void set_tablefunction_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte); static void set_values_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte); -static void set_cte_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte); +static void set_cte_pathlist(PlannerInfo *root, RelOptInfo *rel, + RangeTblEntry *rte); static RelOptInfo *make_rel_from_joinlist(PlannerInfo *root, List *joinlist); static Query *push_down_restrict(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte, Index rti, Query *subquery); diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index abd4b082d6a216d7ae0d8766e28e1873f9078f75..7e2db8014cc716d90a5b683bed67c5b8aeca506d 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -254,8 +254,7 @@ create_subplan(PlannerInfo *root, Path *best_path) case T_Motion: plan = create_motion_plan(root, (CdbMotionPath *)best_path); break; - default: - Assert(false); + default: elog(ERROR, "unrecognized node type: %d", (int) best_path->pathtype); plan = NULL; /* keep compiler quiet */ @@ -267,8 +266,7 @@ create_subplan(PlannerInfo *root, Path *best_path) plan->dispatch = DISPATCH_PARALLEL; return plan; -} /* create_subplan */ - +} /* * create_scan_plan @@ -726,6 +724,7 @@ create_append_plan(PlannerInfo *root, AppendPath *best_path) } plan = make_append(subplans, false, tlist); + return (Plan *) plan; } diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index eb70acd5b9720684f7d218fb98426d2f16f51e72..7c844ffe7ad22cfb7dbdb0c49bb1540e9cd634ce 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -621,6 +621,7 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams) return result; } + /*-------------------- * subquery_planner * Invokes the planner on a subquery. We recurse to here for each @@ -696,7 +697,7 @@ subquery_planner(PlannerGlobal *glob, Query *parse, /* CDB: Stash current query level's relids before pulling up subqueries. */ root->currlevel_relids = get_relids_in_jointree((Node *)parse->jointree); - /* + /* * Look for IN clauses at the top level of WHERE, and transform them into * joins. Note that this step only handles IN clauses originally at top * level of WHERE; if we pull up any subqueries in the next step, their @@ -949,7 +950,7 @@ subquery_planner(PlannerGlobal *glob, Query *parse, * initPlan list and extParam/allParam sets for plan nodes, and attach the * initPlans to the top plan node. */ - if (list_length(glob->subplans) != num_old_subplans || + if (list_length(glob->subplans) != num_old_subplans || root->query_level > 1) { Assert(root->parse == parse); /* GPDP isn't always careful about this. */ @@ -2162,7 +2163,8 @@ grouping_planner(PlannerInfo *root, double tuple_fraction) { result_plan = (Plan *) make_sort_from_pathkeys(root, result_plan, - sort_pathkeys, limit_tuples, false); + sort_pathkeys, + limit_tuples, false); if (result_plan == NULL) elog(ERROR, "could not find sort pathkeys in result target list"); current_pathkeys = sort_pathkeys; diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c index 3b51f1a6dd2c4e1dce14fa1d68c4de9349dea9a9..6df06bdd2e0dd1a6631cd83dbbf31156c428e4b4 100644 --- a/src/backend/optimizer/prep/prepjointree.c +++ b/src/backend/optimizer/prep/prepjointree.c @@ -66,7 +66,7 @@ static void reduce_outer_joins_pass2(Node *jtnode, Relids nonnullable_rels); static void fix_in_clause_relids(List *in_info_list, int varno, Relids subrelids); -static void fix_append_rel_relids(List *append_rel_list, Index varno, +static void fix_append_rel_relids(List *append_rel_list, int varno, Relids subrelids); static Node *find_jointree_node_for_rel(Node *jtnode, int relid); @@ -1215,7 +1215,7 @@ fix_in_clause_relids(List *in_info_list, int varno, Relids subrelids) * We assume we may modify the AppendRelInfo nodes in-place. */ static void -fix_append_rel_relids(List *append_rel_list, Index varno, Relids subrelids) +fix_append_rel_relids(List *append_rel_list, int varno, Relids subrelids) { ListCell *l; int subvarno = -1; diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index 680facb9d2e81f13ff842c5a7f71bc346a246766..670d9e6a3ea3c245124e027d4f83bcb71f3822ae 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -1997,16 +1997,15 @@ eval_const_expressions_mutator(Node *node, if (IsA(node, FuncExpr)) { FuncExpr *expr = (FuncExpr *) node; + List *args; + Expr *simple; + FuncExpr *newexpr; if (!context->transform_functions_returning_composite_values && type_is_rowtype(expr->funcresulttype)) { return copyObject(expr); } - List *args = NIL; - Expr *simple = NULL; - FuncExpr *newexpr = NULL; - /* * Reduce constants in the FuncExpr's arguments. We know args is * either NIL or a List node, so we can call expression_tree_mutator @@ -3238,15 +3237,15 @@ static List * add_function_defaults(List *args, Oid result_type, HeapTuple func_tuple) { Form_pg_proc funcform = (Form_pg_proc) GETSTRUCT(func_tuple); - Datum proargdefaults; - bool isnull; - char *str; - List *defaults; - int ndelete; - int nargs; - Oid actual_arg_types[FUNC_MAX_ARGS]; - Oid declared_arg_types[FUNC_MAX_ARGS]; - Oid rettype; + Datum proargdefaults; + bool isnull; + char *str; + List *defaults; + int ndelete; + int nargs; + Oid actual_arg_types[FUNC_MAX_ARGS]; + Oid declared_arg_types[FUNC_MAX_ARGS]; + Oid rettype; ListCell *lc; /* The error cases here shouldn't happen, but check anyway */ diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 23bb9c93acb78728ec1052df05e0c9a3752acac8..b55be4ab179b78c22b51661178ab606b23a238a4 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -367,12 +367,15 @@ analyze_requires_snapshot(Node *parseTree) break; case T_ExplainStmt: - /* yes, because it's analyzed just like SELECT */ + /* + * We only need a snapshot in varparams case, but it doesn't seem + * worth complicating this function's API to distinguish that. + */ result = true; break; default: - /* other utility statements don't have any active parse analysis */ + /* utility statements don't have any active parse analysis */ result = false; break; } @@ -2843,6 +2846,7 @@ transformReturningList(ParseState *pstate, List *returningList) } #endif + /* * transformDeclareCursorStmt - * transform a DECLARE CURSOR Statement diff --git a/src/backend/parser/parse_clause.c b/src/backend/parser/parse_clause.c index 091e7234a5dc81ca780dea0fa6c81c6de5f4f993..200860d5e32058320e7e70b7e42d4421c0c54d39 100644 --- a/src/backend/parser/parse_clause.c +++ b/src/backend/parser/parse_clause.c @@ -19,19 +19,13 @@ #include "catalog/catquery.h" #include "access/heapam.h" #include "catalog/heap.h" -#include "catalog/pg_am.h" -#include "catalog/pg_amop.h" #include "catalog/pg_exttable.h" -#include "catalog/pg_namespace.h" -#include "catalog/pg_opclass.h" #include "catalog/pg_operator.h" -#include "catalog/pg_proc.h" #include "catalog/pg_type.h" #include "catalog/pg_window.h" #include "commands/defrem.h" #include "nodes/makefuncs.h" #include "nodes/nodeFuncs.h" -#include "nodes/print.h" /* XXX: remove after debugging !! */ #include "optimizer/clauses.h" #include "optimizer/tlist.h" #include "optimizer/var.h" @@ -48,7 +42,6 @@ #include "rewrite/rewriteManip.h" #include "utils/guc.h" #include "utils/lsyscache.h" -#include "utils/syscache.h" #include "cdb/cdbvars.h" #include "cdb/cdbpartition.h" diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c index b2a889b3bd9e25e9b34879dd8339b23ab64ec6c5..5e83b40ae0019aa03303c6f4588d308886cd1051 100644 --- a/src/backend/parser/parse_coerce.c +++ b/src/backend/parser/parse_coerce.c @@ -1372,6 +1372,7 @@ coerce_to_specific_type(ParseState *pstate, Node *node, return node; } + /* select_common_type() * Determine the common supertype of a list of input expression types. * This is used for determining the output type of CASE and UNION diff --git a/src/backend/parser/parse_cte.c b/src/backend/parser/parse_cte.c index 667413f5c360484c972509ff31384a8d220d509e..505bd8ec2fcfde3a8948ab07e8dba2ee3f5a764c 100644 --- a/src/backend/parser/parse_cte.c +++ b/src/backend/parser/parse_cte.c @@ -6,11 +6,11 @@ */ #include "postgres.h" +#include "parser/analyze.h" #include "parser/parse_node.h" #include "parser/parse_cte.h" #include "parser/parse_expr.h" #include "parser/parse_relation.h" -#include "parser/analyze.h" #include "nodes/parsenodes.h" #include "nodes/nodeFuncs.h" @@ -29,6 +29,8 @@ static void analyzeCTETargetList(ParseState *pstate, CommonTableExpr *cte, List List * transformWithClause(ParseState *pstate, WithClause *withClause) { + ListCell *lc; + if (withClause == NULL) return NULL; @@ -44,22 +46,19 @@ transformWithClause(ParseState *pstate, WithClause *withClause) Assert(pstate->p_future_ctes == NIL); /* - * Check if CTE list in the WITH clause contains duplicate query names. - * If so, error out. + * For either type of WITH, there must not be duplicate CTE names in the + * list. Check this right away so we needn't worry later. * * Also, initialize other variables in CommonTableExpr. */ - ListCell *lc; - foreach (lc, withClause->ctes) + foreach(lc, withClause->ctes) { - CommonTableExpr *cte = (CommonTableExpr *)lfirst(lc); + CommonTableExpr *cte = (CommonTableExpr *) lfirst(lc); + ListCell *rest; - ListCell *lc2; - for_each_cell (lc2, lnext(lc)) + for_each_cell(rest, lnext(lc)) { - CommonTableExpr *cte2 = (CommonTableExpr *)lfirst(lc2); - Assert(cte != NULL && cte2 != NULL && - cte->ctename != NULL && cte2->ctename != NULL); + CommonTableExpr *cte2 = (CommonTableExpr *) lfirst(rest); if (strcmp(cte->ctename, cte2->ctename) == 0) { @@ -69,7 +68,6 @@ transformWithClause(ParseState *pstate, WithClause *withClause) cte2->ctename), parser_errposition(pstate, cte2->location))); } - } cte->cterecursive = false; @@ -154,14 +152,16 @@ GetCTEForRTE(ParseState *pstate, RangeTblEntry *rte, int rtelevelsup) static void analyzeCTE(ParseState *pstate, CommonTableExpr *cte) { + Query *query; + Assert(cte != NULL); Assert(cte->ctequery != NULL); Assert(!IsA(cte->ctequery, Query)); - Query *query = parse_sub_analyze(cte->ctequery, pstate); - Assert(IsA(query, Query)); + query = parse_sub_analyze(cte->ctequery, pstate); + cte->ctequery = (Node *) query; - cte->ctequery = (Node *)query; + Assert(IsA(query, Query)); /* Check if the query is what we expected. */ if (!IsA(query, Query)) @@ -226,27 +226,29 @@ reportDuplicateNames(const char *queryName, List *names) static void analyzeCTETargetList(ParseState *pstate, CommonTableExpr *cte, List *tlist) { + int numaliases; + int varattno; + ListCell *tlistitem; + + /* Not done already ... */ Assert(cte->ctecolnames == NIL); /* - * We need to determine column names, types, and typmods. The alias - * column names override anything coming from the query itself. (Note: - * the SQL spec says that the alias list must be empty or exactly as long - * as the output column set. Also, the alias can not have the same name. - * We report errors if this is not the case.) - * + * We need to determine column names and types. The alias column names + * override anything coming from the query itself. (Note: the SQL spec + * says that the alias list must be empty or exactly as long as the output + * column set. Also, the alias can not have the same name. We report + * errors if this is not the case.) */ cte->ctecolnames = copyObject(cte->aliascolnames); cte->ctecoltypes = cte->ctecoltypmods = NIL; - int numaliases = list_length(cte->aliascolnames); - - int varattno = 0; - ListCell *tlistitem; + numaliases = list_length(cte->aliascolnames); + varattno = 0; foreach(tlistitem, tlist) { TargetEntry *te = (TargetEntry *) lfirst(tlistitem); - Oid coltype; - int32 coltypmod; + Oid coltype; + int32 coltypmod; if (te->resjunk) continue; @@ -254,6 +256,8 @@ analyzeCTETargetList(ParseState *pstate, CommonTableExpr *cte, List *tlist) Assert(varattno == te->resno); if (varattno > numaliases) { + char *attrname; + if (numaliases > 0) { ereport(ERROR, @@ -261,8 +265,6 @@ analyzeCTETargetList(ParseState *pstate, CommonTableExpr *cte, List *tlist) errmsg(ERRMSG_GP_WITH_COLUMNS_MISMATCH, cte->ctename), parser_errposition(pstate, cte->location))); } - - char *attrname; attrname = pstrdup(te->resname); cte->ctecolnames = lappend(cte->ctecolnames, makeString(attrname)); diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index 5fb93df296c4bf96b709a88f7e2e09cd5144c6d9..f428bb2efbcf9523870ef6d278bb7d53f8f635d1 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -58,7 +58,7 @@ static Node *transformAExprIn(ParseState *pstate, A_Expr *a); static Node *transformFuncCall(ParseState *pstate, FuncCall *fn); static Node *transformSubLink(ParseState *pstate, SubLink *sublink); static Node *transformArrayExpr(ParseState *pstate, A_ArrayExpr *a, - Oid array_type, Oid element_type, int32 typmod); + Oid array_type, Oid element_type, int32 typmod); static Node *transformRowExpr(ParseState *pstate, RowExpr *r); static Node *transformTableValueExpr(ParseState *pstate, TableValueExpr *t); static Node *transformCoalesceExpr(ParseState *pstate, CoalesceExpr *c); @@ -112,11 +112,6 @@ static char *percentileFuncString(PercentileExpr *p, Oid *argtypes, int arglen, * another, such as A_Const => Const; we just do nothing when handed * a Const. More care is needed for node types that are used as both * input and output of transformExpr; see SubLink for example. - * - * CDB: On return, pstate->breadcrumb.node points to the original 'expr' node. - * This is intended to provide a default cursor location in case an error is - * reported during further processing of the result, such as conversion to a - * target type. */ Node * transformExpr(ParseState *pstate, Node *expr) @@ -163,10 +158,10 @@ transformExpr(ParseState *pstate, Node *expr) break; } - case T_A_ArrayExpr: - result = transformArrayExpr(pstate, (A_ArrayExpr *) expr, - InvalidOid, InvalidOid, -1); - break; + case T_A_ArrayExpr: + result = transformArrayExpr(pstate, (A_ArrayExpr *) expr, + InvalidOid, InvalidOid, -1); + break; case T_TypeCast: { @@ -174,19 +169,20 @@ transformExpr(ParseState *pstate, Node *expr) Node *arg = NULL; /* - * If the subject of the typecast is an ARRAY[] construct - * and the target type is an array type, we invoke - * transformArrayExpr() directly so that we can pass down - * the type information. This avoids some cases where - * transformArrayExpr() might not infer the correct type - */ + * If the subject of the typecast is an ARRAY[] construct and + * the target type is an array type, we invoke + * transformArrayExpr() directly so that we can pass down the + * type information. This avoids some cases where + * transformArrayExpr() might not infer the correct type. + */ if (IsA(tc->arg, A_ArrayExpr)) { - Oid targetType; - Oid elementType; - int32 targetTypmod; + Oid targetType; + Oid elementType; + int32 targetTypmod; - targetType = typenameTypeId(pstate, tc->typname, &targetTypmod); + targetType = typenameTypeId(pstate, tc->typname, + &targetTypmod); elementType = get_element_type(targetType); if (OidIsValid(elementType)) @@ -260,7 +256,6 @@ transformExpr(ParseState *pstate, Node *expr) result = transformFuncCall(pstate, (FuncCall *) expr); break; - case T_SubLink: result = transformSubLink(pstate, (SubLink *) expr); break; @@ -1527,7 +1522,6 @@ transformSubLink(ParseState *pstate, SubLink *sublink) return result; pstate->p_hasSubLinks = true; - qtree = parse_sub_analyze(sublink->subselect, pstate); /* @@ -1651,9 +1645,16 @@ transformSubLink(ParseState *pstate, SubLink *sublink) return result; } +/* + * transformArrayExpr + * + * If the caller specifies the target type, the resulting array will + * be of exactly that type. Otherwise we try to infer a common type + * for the elements using select_common_type(). + */ static Node * transformArrayExpr(ParseState *pstate, A_ArrayExpr *a, - Oid array_type, Oid element_type, int32 typmod) + Oid array_type, Oid element_type, int32 typmod) { ArrayExpr *newa = makeNode(ArrayExpr); List *newelems = NIL; @@ -1669,7 +1670,7 @@ transformArrayExpr(ParseState *pstate, A_ArrayExpr *a, * Assume that the array is one-dimensional unless we find an array-type * element expression. */ - newa->multidims = false; + newa->multidims = false; foreach(element, a->elements) { Node *e = (Node *) lfirst(element); @@ -1683,10 +1684,10 @@ transformArrayExpr(ParseState *pstate, A_ArrayExpr *a, if (IsA(e, A_ArrayExpr)) { newe = transformArrayExpr(pstate, - (A_ArrayExpr *) e, - array_type, - element_type, - typmod); + (A_ArrayExpr *) e, + array_type, + element_type, + typmod); newe_type = exprType(newe); /* we certainly have an array here */ Assert(array_type == InvalidOid || array_type == newe_type); @@ -1768,7 +1769,6 @@ transformArrayExpr(ParseState *pstate, A_ArrayExpr *a, * elements, then the elements are implicitly coerced to the common type. * This is consistent with other uses of select_common_type(). */ - foreach(element, newelems) { Node *e = (Node *) lfirst(element); @@ -1781,8 +1781,8 @@ transformArrayExpr(ParseState *pstate, A_ArrayExpr *a, coerce_type, typmod, COERCION_EXPLICIT, - COERCE_EXPLICIT_CAST,-1); - + COERCE_EXPLICIT_CAST, + -1); if (newe == NULL) ereport(ERROR, (errcode(ERRCODE_CANNOT_COERCE), @@ -2119,7 +2119,8 @@ transformXmlSerialize(ParseState *pstate, XmlSerialize *xs) */ result = coerce_to_target_type(pstate, (Node *) xexpr, TEXTOID, targetType, targetTypmod, - COERCION_IMPLICIT, COERCE_IMPLICIT_CAST, + COERCION_IMPLICIT, + COERCE_IMPLICIT_CAST, xexpr->location); if (result == NULL) ereport(ERROR, @@ -2242,7 +2243,8 @@ transformWholeRowRef(ParseState *pstate, char *schemaname, char *relname, &sublevels_up); if (rte == NULL) - rte = addImplicitRTE(pstate, makeRangeVar(schemaname, relname, location)); + rte = addImplicitRTE(pstate, + makeRangeVar(schemaname, relname, location)); vnum = RTERangeTablePosn(pstate, rte, &sublevels_up); @@ -3449,7 +3451,8 @@ make_row_distinct_op(ParseState *pstate, List *opname, result = cmp; else result = (Node *) makeBoolExpr(OR_EXPR, - list_make2(result, cmp), location); + list_make2(result, cmp), + location); } if (result == NULL) diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c index 27f2792a241843c66fb3cb0c233e55dd5cac3c35..cbec6d7bbb1b6b3fabf119102c767b655c822461 100644 --- a/src/backend/parser/parse_relation.c +++ b/src/backend/parser/parse_relation.c @@ -17,16 +17,12 @@ #include -#include "access/genam.h" #include "access/heapam.h" #include "catalog/heap.h" #include "catalog/namespace.h" -#include "catalog/pg_exttable.h" #include "catalog/pg_proc_callback.h" #include "catalog/pg_type.h" -#include "catalog/indexing.h" #include "funcapi.h" -#include "miscadmin.h" #include "nodes/makefuncs.h" #include "nodes/nodeFuncs.h" #include "nodes/relation.h" /* CdbRelColumnInfo */ @@ -36,12 +32,9 @@ #include "parser/parse_relation.h" #include "parser/parse_type.h" #include "parser/parse_coerce.h" -#include "utils/acl.h" #include "utils/builtins.h" #include "utils/lsyscache.h" #include "utils/syscache.h" -#include "utils/array.h" -#include "utils/fmgroids.h" /* GUC parameter */ @@ -201,24 +194,20 @@ scanNameSpaceForRelid(ParseState *pstate, Oid relid, int location) * rejects WITH lists containing duplicate CTE names. */ CommonTableExpr * -scanNameSpaceForCTE(ParseState *pstate, - const char *refname, +scanNameSpaceForCTE(ParseState *pstate, const char *refname, Index *ctelevelsup) { - Assert(refname != NULL); - - Index levelsup; + Index levelsup; for (levelsup = 0; pstate != NULL; pstate = pstate->parentParseState, levelsup++) { - ListCell *lc; + ListCell *lc; foreach(lc, pstate->p_ctenamespace) { CommonTableExpr *cte = (CommonTableExpr *) lfirst(lc); - Assert(cte != NULL && cte->ctename != NULL); if (strcmp(cte->ctename, refname) == 0) { @@ -227,7 +216,6 @@ scanNameSpaceForCTE(ParseState *pstate, } } } - return NULL; } @@ -266,16 +254,17 @@ isFutureCTE(ParseState *pstate, const char *refname) * valid matches, but only one will be returned). This must be used ONLY * as a heuristic in giving suitable error messages. See warnAutoRange. * - * Notice that we consider both matches on actual relation name (or CTE) and matches - * on alias. + * Notice that we consider both matches on actual relation (or CTE) name + * and matches on alias. */ static RangeTblEntry * searchRangeTable(ParseState *pstate, RangeVar *relation) { - Oid relId = InvalidOid; const char *refname = relation->relname; + Oid relId = InvalidOid; CommonTableExpr *cte = NULL; - Index ctelevelsup = 0; + Index ctelevelsup = 0; + Index levelsup; /* * If it's an unqualified name, check for possible CTE matches. A CTE @@ -287,8 +276,10 @@ searchRangeTable(ParseState *pstate, RangeVar *relation) if (!cte) relId = RangeVarGetRelid(relation, true); - Index levelsup = 0; - while (pstate != NULL) + /* Now look for RTEs matching either the relation/CTE or the alias */ + for (levelsup = 0; + pstate != NULL; + pstate = pstate->parentParseState, levelsup++) { ListCell *l; @@ -296,11 +287,10 @@ searchRangeTable(ParseState *pstate, RangeVar *relation) { RangeTblEntry *rte = (RangeTblEntry *) lfirst(l); - if (OidIsValid(relId) && - rte->rtekind == RTE_RELATION && + if (rte->rtekind == RTE_RELATION && + OidIsValid(relId) && rte->relid == relId) return rte; - if (rte->rtekind == RTE_CTE && cte != NULL && rte->ctelevelsup + levelsup == ctelevelsup && @@ -312,9 +302,6 @@ searchRangeTable(ParseState *pstate, RangeVar *relation) strcmp(rte->eref->aliasname, refname) == 0) return rte; } - - pstate = pstate->parentParseState; - levelsup++; } return NULL; } @@ -764,15 +751,15 @@ addRangeTableEntry(ParseState *pstate, bool inh, bool inFromCl) { - RangeTblEntry *rte = makeNode(RangeTblEntry); - char *refname = alias ? alias->aliasname : relation->relname; - LOCKMODE lockmode = AccessShareLock; - bool nowait = false; - LockingClause *locking; - Relation rel; - ParseCallbackState pcbstate; - - /* + RangeTblEntry *rte = makeNode(RangeTblEntry); + char *refname = alias ? alias->aliasname : relation->relname; + LOCKMODE lockmode = AccessShareLock; + bool nowait = false; + LockingClause *locking; + Relation rel; + ParseCallbackState pcbstate; + + /* * CDB: lock promotion around the locking clause is a little different * from postgres to allow for required lock promotion for distributed * tables. @@ -786,7 +773,7 @@ addRangeTableEntry(ParseState *pstate, setup_parser_errposition_callback(&pcbstate, pstate, relation->location); rel = parserOpenTable(pstate, relation, lockmode, nowait, NULL); cancel_parser_errposition_callback(&pcbstate); - + /* * Get the rel's OID. This access also ensures that we have an up-to-date * relcache entry for the rel. Since this is typically the first access @@ -1373,6 +1360,11 @@ addRangeTableEntryForCTE(ParseState *pstate, bool inFromCl) { RangeTblEntry *rte = makeNode(RangeTblEntry); + char *refname; + Alias *eref; + int numaliases; + int varattno; + ListCell *lc; rte->rtekind = RTE_CTE; rte->ctename = cte->ctename; @@ -1393,18 +1385,15 @@ addRangeTableEntryForCTE(ParseState *pstate, rte->ctecoltypmods = cte->ctecoltypmods; rte->alias = rangeVar->alias; - char *refname = rte->alias ? rte->alias->aliasname : cte->ctename; - Alias *eref; - + refname = rte->alias ? rte->alias->aliasname : cte->ctename; if (rte->alias) eref = copyObject(rte->alias); else eref = makeAlias(refname, NIL); - int numaliases = list_length(eref->colnames); + numaliases = list_length(eref->colnames); /* fill in any unspecified alias columns */ - int varattno = 0; - ListCell *lc; + varattno = 0; foreach(lc, cte->ctecolnames) { varattno++; @@ -2299,7 +2288,7 @@ get_rte_attribute_is_dropped(RangeTblEntry *rte, AttrNumber attnum) case RTE_SUBQUERY: case RTE_VALUES: case RTE_CTE: - /* Subselect and Values RTEs never have dropped columns */ + /* Subselect, Values, CTE RTEs never have dropped columns */ result = false; break; case RTE_JOIN: diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c index 18c5a71c20119dde077b76bd79a6ef28d3348b96..85ef2b352d16c5e4bd6edfc8d6996e5813d8e8cc 100644 --- a/src/backend/parser/parse_target.c +++ b/src/backend/parser/parse_target.c @@ -1127,7 +1127,7 @@ expandRecordVariable(ParseState *pstate, Var *var, int levelsup) char *label = strVal(lfirst(lname)); Node *varnode = (Node *) lfirst(lvar); - TupleDescInitEntry(tupleDesc, (AttrNumber) i, + TupleDescInitEntry(tupleDesc, i, label, exprType(varnode), exprTypmod(varnode), diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index cf38c90f5fe35113b1e26c128ee7c35ecef2d669..ed57b1aaed4913b5834ccadc5407f639a95cda4f 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -2461,7 +2461,6 @@ transformFKConstraints(ParseState *pstate, CreateStmtContext *cxt, } } - /* * transformIndexStmt - parse analysis for CREATE INDEX * @@ -3521,6 +3520,10 @@ transformCreateSchemaStmt(CreateSchemaStmt *stmt) return result; } +/* + * setSchemaName + * Set or check schema name in an element of a CREATE SCHEMA command + */ static void setSchemaName(char *context_schema, char **stmt_schema_name) { diff --git a/src/backend/storage/buffer/bufmgr.c b/src/backend/storage/buffer/bufmgr.c index f1ab3cdf69a681988731f37e3f2a529915112459..ae6af00d2a9906b3146a7f4ec47e391b0a065d5a 100644 --- a/src/backend/storage/buffer/bufmgr.c +++ b/src/backend/storage/buffer/bufmgr.c @@ -87,6 +87,7 @@ static bool IsForInput; /* local state for LockBufferForCleanup */ static volatile BufferDesc *PinCountWaitBuf = NULL; + static Buffer ReadBuffer_common(SMgrRelation reln, bool isLocalBuf, bool isTemp, BlockNumber blockNum, bool zeroPage, BufferAccessStrategy strategy, @@ -101,11 +102,9 @@ static bool StartBufferIO(volatile BufferDesc *buf, bool forInput); static void TerminateBufferIO(volatile BufferDesc *buf, bool clear_dirty, int set_flag_bits); static void buffer_write_error_callback(void *arg); - static volatile BufferDesc *BufferAlloc(SMgrRelation reln, BlockNumber blockNum, BufferAccessStrategy strategy, bool *foundPtr); - static void FlushBuffer(volatile BufferDesc *buf, SMgrRelation reln); static void AtProcExit_Buffers(int code, Datum arg); @@ -1215,7 +1214,6 @@ BufferSync(int flags) /* Make sure we can handle the pin inside SyncOneBuffer */ ResourceOwnerEnlargeBuffers(CurrentResourceOwner); - /* * Loop over all buffers, and mark the ones that need to be written with * BM_CHECKPOINT_NEEDED. Count them as we go (num_to_write), so that we @@ -1664,7 +1662,7 @@ SyncOneBuffer(int buf_id, bool skip_recently_used) return result; } - + /* * Pin it, share-lock it, write it. (FlushBuffer will do nothing if the * buffer is clean by the time we've locked it.) @@ -2116,12 +2114,12 @@ RelationTruncate(Relation rel, BlockNumber nblocks, bool markPersistentAsPhysica * -------------------------------------------------------------------- */ void -DropRelFileNodeBuffers(RelFileNode rnode, bool isLocalBuf, +DropRelFileNodeBuffers(RelFileNode rnode, bool istemp, BlockNumber firstDelBlock) { int i; - if (isLocalBuf) /*CDB*/ + if (istemp) { DropRelFileNodeLocalBuffers(rnode, firstDelBlock); return; @@ -2401,7 +2399,6 @@ ReleaseBuffer(Buffer buffer) UnpinBuffer(bufHdr, false); } - /* * UnlockReleaseBuffer -- release the content lock and pin on a buffer * diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 0301255b40c44d65866908c6bc953b4a3f6311b5..411f3f467f5ce9e8a5fb40bae88913244efb483e 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -187,6 +187,7 @@ static int recursion_depth = 0; /* to detect actual recursion */ static char formatted_start_time[FORMATTED_TS_LEN]; static char formatted_log_time[FORMATTED_TS_LEN]; + /* Macro for checking errordata_stack_depth is reasonable */ #define CHECK_STACK_DEPTH() \ do { \ @@ -197,6 +198,7 @@ static char formatted_log_time[FORMATTED_TS_LEN]; } \ } while (0) + static void cdb_tidy_message(ErrorData *edata); static void log_line_prefix(StringInfo buf); static void send_message_to_server_log(ErrorData *edata); @@ -2424,7 +2426,7 @@ log_line_prefix(StringInfo buf) if (MyProcPort) { const char *psdisp; - int displen; + int displen; psdisp = get_ps_display(&displen); appendBinaryStringInfo(buf, psdisp, displen); @@ -2698,7 +2700,7 @@ write_csvlog(ErrorData *edata) psdisp = get_ps_display(&displen); appendBinaryStringInfo(&msgbuf, psdisp, displen); appendCSVLiteral(&buf, msgbuf.data); - + pfree(msgbuf.data); } appendStringInfoChar(&buf, ','); @@ -3485,9 +3487,9 @@ write_message_to_server_log(int elevel, static void send_message_to_server_log(ErrorData *edata) { - StringInfoData buf; - StringInfoData prefix; - int nc; + StringInfoData buf; + StringInfoData prefix; + int nc; AssertImply(mainthread() != 0, mythread() == mainthread()); diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index a827025a7726a0f3c8d5a0fd5f3d3a1c95b67842..5a44e4c6fd04bf20559769c48aa9547775b93c88 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -560,7 +560,7 @@ static struct config_bool ConfigureNamesBool[] = {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER, gettext_noop("Enables the planner to use constraints to optimize queries."), gettext_noop("Child table scans will be skipped if their " - "constraints guarantee that no rows match the query."), + "constraints guarantee that no rows match the query."), GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE }, &constraint_exclusion, @@ -1453,7 +1453,7 @@ static struct config_int ConfigureNamesInt[] = { {"max_prepared_transactions", PGC_POSTMASTER, RESOURCES, gettext_noop("Sets the maximum number of simultaneously prepared transactions."), - NULL + NULL }, &max_prepared_xacts, 50, 1, 1000, NULL, NULL @@ -1780,7 +1780,7 @@ static struct config_int ConfigureNamesInt[] = GUC_NOT_IN_SAMPLE | GUC_NO_SHOW_ALL }, &autovacuum_freeze_max_age, - 200000000, 1000, 2000000000, NULL, NULL + 200000000, 100000000, 2000000000, NULL, NULL }, { /* see max_connections */ @@ -1977,7 +1977,7 @@ static struct config_real ConfigureNamesReal[] = { {"geqo_selection_bias", PGC_USERSET, DEFUNCT_OPTIONS, gettext_noop("Unused. Syntax check only for PostgreSQL compatibility."), - NULL, + NULL, GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE }, &defunct_double, @@ -2203,7 +2203,7 @@ static struct config_string ConfigureNamesString[] = {"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT, gettext_noop("Sets the transaction isolation level of each new transaction."), gettext_noop("Each SQL transaction has an isolation level, which " - "can be either \"read uncommitted\", \"read committed\", \"repeatable read\", or \"serializable\"."), + "can be either \"read uncommitted\", \"read committed\", \"repeatable read\", or \"serializable\".") }, &default_iso_level_string, "read committed", assign_defaultxactisolevel, NULL @@ -2644,7 +2644,7 @@ static struct config_string ConfigureNamesString[] = &external_pid_file, NULL, assign_canonical_path, NULL }, - + /* End-of-list marker */ { {NULL, 0, 0, NULL, NULL}, NULL, NULL, NULL, NULL @@ -3504,7 +3504,7 @@ InitializeGUCOptions(void) bool SelectConfigFiles(const char *userDoption, const char *progname) { - char *configdir = NULL; + char *configdir; char *fname; struct stat stat_buf; @@ -4384,9 +4384,9 @@ parse_int(const char *value, int *result, int flags, const char **hintmsg) /* - * Try to parse value as a floating point constant in the usual - * format. If the value parsed okay return true, else false. If - * result is not NULL, return the semantic value there. + * Try to parse value as a floating point number in the usual format. + * If the string parses okay, return true, else false. + * If okay and result is not NULL, return the value in *result. */ static bool parse_real(const char *value, double *result) @@ -5502,8 +5502,6 @@ ExtractSetVariableArgs(VariableSetStmt *stmt) } } - - /* * SetPGVariable - SET command exported as an easily-C-callable function. * @@ -6798,6 +6796,7 @@ ParseLongOption(const char *string, char **name, char **value) *cp = '_'; } + /* * Handle options fetched from pg_database.datconfig, pg_authid.rolconfig, * pg_proc.proconfig, etc. Caller must specify proper context/source/action. @@ -7088,6 +7087,7 @@ GUCArrayReset(ArrayType *array) return newarray; } + /* * assign_hook and show_hook subroutines */ diff --git a/src/include/parser/parse_type.h b/src/include/parser/parse_type.h index e5ac4201389cc0b7135ace56d57e7faca898930c..e4e7ffb67ec560822f741b5419c81aa23ca34cfa 100644 --- a/src/include/parser/parse_type.h +++ b/src/include/parser/parse_type.h @@ -44,6 +44,6 @@ extern Oid typeidTypeRelid(Oid type_id); extern void parseTypeString(const char *str, Oid *type_id, int32 *typmod_p); -#define ISCOMPLEX(typid) (typeidTypeRelid(typid) != InvalidOid) +#define ISCOMPLEX(typeid) (typeidTypeRelid(typeid) != InvalidOid) #endif /* PARSE_TYPE_H */