]> granicus.if.org Git - postgresql/blobdiff - src/backend/nodes/outfuncs.c
Fix PARAM_EXEC assignment mechanism to be safe in the presence of WITH.
[postgresql] / src / backend / nodes / outfuncs.c
index 9daeb3e7b43e911aeab25b7521d41191928499bd..02a0f62a53a4e3d06a3ad48d523e959d5d6b2ab7 100644 (file)
@@ -141,7 +141,7 @@ _outToken(StringInfo str, const char *s)
 static void
 _outList(StringInfo str, const List *node)
 {
-       const ListCell   *lc;
+       const ListCell *lc;
 
        appendStringInfoChar(str, '(');
 
@@ -242,6 +242,7 @@ _outPlannedStmt(StringInfo str, const PlannedStmt *node)
        WRITE_NODE_TYPE("PLANNEDSTMT");
 
        WRITE_ENUM_FIELD(commandType, CmdType);
+       WRITE_UINT_FIELD(queryId);
        WRITE_BOOL_FIELD(hasReturning);
        WRITE_BOOL_FIELD(hasModifyingCTE);
        WRITE_BOOL_FIELD(canSetTag);
@@ -250,7 +251,6 @@ _outPlannedStmt(StringInfo str, const PlannedStmt *node)
        WRITE_NODE_FIELD(rtable);
        WRITE_NODE_FIELD(resultRelations);
        WRITE_NODE_FIELD(utilityStmt);
-       WRITE_NODE_FIELD(intoClause);
        WRITE_NODE_FIELD(subplans);
        WRITE_BITMAPSET_FIELD(rewindPlanIDs);
        WRITE_NODE_FIELD(rowMarks);
@@ -559,8 +559,9 @@ _outForeignScan(StringInfo str, const ForeignScan *node)
 
        _outScanInfo(str, (const Scan *) node);
 
-       WRITE_BOOL_FIELD(fsSystemCol);
+       WRITE_NODE_FIELD(fdw_exprs);
        WRITE_NODE_FIELD(fdw_private);
+       WRITE_BOOL_FIELD(fsSystemCol);
 }
 
 static void
@@ -1460,6 +1461,9 @@ _outFromExpr(StringInfo str, const FromExpr *node)
  *
  * Note we do NOT print the parent, else we'd be in infinite recursion.
  * We can print the parent's relids for identification purposes, though.
+ * We also do not print the whole of param_info, since it's printed by
+ * _outRelOptInfo; it's sufficient and less cluttering to print just the
+ * required outer relids.
  */
 static void
 _outPathInfo(StringInfo str, const Path *node)
@@ -1467,12 +1471,15 @@ _outPathInfo(StringInfo str, const Path *node)
        WRITE_ENUM_FIELD(pathtype, NodeTag);
        appendStringInfo(str, " :parent_relids ");
        _outBitmapset(str, node->parent->relids);
+       appendStringInfo(str, " :required_outer ");
+       if (node->param_info)
+               _outBitmapset(str, node->param_info->ppi_req_outer);
+       else
+               _outBitmapset(str, NULL);
        WRITE_FLOAT_FIELD(rows, "%.0f");
        WRITE_FLOAT_FIELD(startup_cost, "%.2f");
        WRITE_FLOAT_FIELD(total_cost, "%.2f");
        WRITE_NODE_FIELD(pathkeys);
-       WRITE_BITMAPSET_FIELD(required_outer);
-       WRITE_NODE_FIELD(param_clauses);
 }
 
 /*
@@ -1659,7 +1666,6 @@ _outPlannerGlobal(StringInfo str, const PlannerGlobal *node)
        WRITE_NODE_TYPE("PLANNERGLOBAL");
 
        /* NB: this isn't a complete set of fields */
-       WRITE_NODE_FIELD(paramlist);
        WRITE_NODE_FIELD(subplans);
        WRITE_BITMAPSET_FIELD(rewindPlanIDs);
        WRITE_NODE_FIELD(finalrtable);
@@ -1667,6 +1673,7 @@ _outPlannerGlobal(StringInfo str, const PlannerGlobal *node)
        WRITE_NODE_FIELD(resultRelations);
        WRITE_NODE_FIELD(relationOids);
        WRITE_NODE_FIELD(invalItems);
+       WRITE_INT_FIELD(nParamExec);
        WRITE_UINT_FIELD(lastPHId);
        WRITE_UINT_FIELD(lastRowMarkId);
        WRITE_BOOL_FIELD(transientPlan);
@@ -1681,6 +1688,7 @@ _outPlannerInfo(StringInfo str, const PlannerInfo *node)
        WRITE_NODE_FIELD(parse);
        WRITE_NODE_FIELD(glob);
        WRITE_UINT_FIELD(query_level);
+       WRITE_NODE_FIELD(plan_params);
        WRITE_BITMAPSET_FIELD(all_baserels);
        WRITE_NODE_FIELD(join_rel_list);
        WRITE_INT_FIELD(join_cur_level);
@@ -1692,6 +1700,7 @@ _outPlannerInfo(StringInfo str, const PlannerInfo *node)
        WRITE_NODE_FIELD(right_join_clauses);
        WRITE_NODE_FIELD(full_join_clauses);
        WRITE_NODE_FIELD(join_info_list);
+       WRITE_NODE_FIELD(lateral_info_list);
        WRITE_NODE_FIELD(append_rel_list);
        WRITE_NODE_FIELD(rowMarks);
        WRITE_NODE_FIELD(placeholder_list);
@@ -1706,6 +1715,7 @@ _outPlannerInfo(StringInfo str, const PlannerInfo *node)
        WRITE_FLOAT_FIELD(limit_tuples, "%.0f");
        WRITE_BOOL_FIELD(hasInheritedTarget);
        WRITE_BOOL_FIELD(hasJoinRTEs);
+       WRITE_BOOL_FIELD(hasLateralRTEs);
        WRITE_BOOL_FIELD(hasHavingQual);
        WRITE_BOOL_FIELD(hasPseudoConstantQuals);
        WRITE_BOOL_FIELD(hasRecursion);
@@ -1724,8 +1734,10 @@ _outRelOptInfo(StringInfo str, const RelOptInfo *node)
        WRITE_BITMAPSET_FIELD(relids);
        WRITE_FLOAT_FIELD(rows, "%.0f");
        WRITE_INT_FIELD(width);
+       WRITE_BOOL_FIELD(consider_startup);
        WRITE_NODE_FIELD(reltargetlist);
        WRITE_NODE_FIELD(pathlist);
+       WRITE_NODE_FIELD(ppilist);
        WRITE_NODE_FIELD(cheapest_startup_path);
        WRITE_NODE_FIELD(cheapest_total_path);
        WRITE_NODE_FIELD(cheapest_unique_path);
@@ -1735,12 +1747,16 @@ _outRelOptInfo(StringInfo str, const RelOptInfo *node)
        WRITE_ENUM_FIELD(rtekind, RTEKind);
        WRITE_INT_FIELD(min_attr);
        WRITE_INT_FIELD(max_attr);
+       WRITE_NODE_FIELD(lateral_vars);
+       WRITE_BITMAPSET_FIELD(lateral_relids);
        WRITE_NODE_FIELD(indexlist);
        WRITE_UINT_FIELD(pages);
        WRITE_FLOAT_FIELD(tuples, "%.0f");
        WRITE_FLOAT_FIELD(allvisfrac, "%.6f");
        WRITE_NODE_FIELD(subplan);
        WRITE_NODE_FIELD(subroot);
+       WRITE_NODE_FIELD(subplan_params);
+       /* we don't try to print fdwroutine or fdw_private */
        WRITE_NODE_FIELD(baserestrictinfo);
        WRITE_NODE_FIELD(joininfo);
        WRITE_BOOL_FIELD(has_eclass_joins);
@@ -1815,6 +1831,16 @@ _outPathKey(StringInfo str, const PathKey *node)
        WRITE_BOOL_FIELD(pk_nulls_first);
 }
 
+static void
+_outParamPathInfo(StringInfo str, const ParamPathInfo *node)
+{
+       WRITE_NODE_TYPE("PARAMPATHINFO");
+
+       WRITE_BITMAPSET_FIELD(ppi_req_outer);
+       WRITE_FLOAT_FIELD(ppi_rows, "%.0f");
+       WRITE_NODE_FIELD(ppi_clauses);
+}
+
 static void
 _outRestrictInfo(StringInfo str, const RestrictInfo *node)
 {
@@ -1828,6 +1854,7 @@ _outRestrictInfo(StringInfo str, const RestrictInfo *node)
        WRITE_BOOL_FIELD(pseudoconstant);
        WRITE_BITMAPSET_FIELD(clause_relids);
        WRITE_BITMAPSET_FIELD(required_relids);
+       WRITE_BITMAPSET_FIELD(outer_relids);
        WRITE_BITMAPSET_FIELD(nullable_relids);
        WRITE_BITMAPSET_FIELD(left_relids);
        WRITE_BITMAPSET_FIELD(right_relids);
@@ -1870,6 +1897,15 @@ _outSpecialJoinInfo(StringInfo str, const SpecialJoinInfo *node)
        WRITE_NODE_FIELD(join_quals);
 }
 
+static void
+_outLateralJoinInfo(StringInfo str, const LateralJoinInfo *node)
+{
+       WRITE_NODE_TYPE("LATERALJOININFO");
+
+       WRITE_UINT_FIELD(lateral_rhs);
+       WRITE_BITMAPSET_FIELD(lateral_lhs);
+}
+
 static void
 _outAppendRelInfo(StringInfo str, const AppendRelInfo *node)
 {
@@ -1916,7 +1952,7 @@ _outPlannerParamItem(StringInfo str, const PlannerParamItem *node)
        WRITE_NODE_TYPE("PLANNERPARAMITEM");
 
        WRITE_NODE_FIELD(item);
-       WRITE_UINT_FIELD(abslevel);
+       WRITE_INT_FIELD(paramId);
 }
 
 /*****************************************************************************
@@ -1925,11 +1961,12 @@ _outPlannerParamItem(StringInfo str, const PlannerParamItem *node)
  *
  *****************************************************************************/
 
+/*
+ * print the basic stuff of all nodes that inherit from CreateStmt
+ */
 static void
-_outCreateStmt(StringInfo str, const CreateStmt *node)
+_outCreateStmtInfo(StringInfo str, const CreateStmt *node)
 {
-       WRITE_NODE_TYPE("CREATESTMT");
-
        WRITE_NODE_FIELD(relation);
        WRITE_NODE_FIELD(tableElts);
        WRITE_NODE_FIELD(inhRelations);
@@ -1941,12 +1978,20 @@ _outCreateStmt(StringInfo str, const CreateStmt *node)
        WRITE_BOOL_FIELD(if_not_exists);
 }
 
+static void
+_outCreateStmt(StringInfo str, const CreateStmt *node)
+{
+       WRITE_NODE_TYPE("CREATESTMT");
+
+       _outCreateStmtInfo(str, (const CreateStmt *) node);
+}
+
 static void
 _outCreateForeignTableStmt(StringInfo str, const CreateForeignTableStmt *node)
 {
        WRITE_NODE_TYPE("CREATEFOREIGNTABLESTMT");
 
-       _outCreateStmt(str, (const CreateStmt *) &node->base);
+       _outCreateStmtInfo(str, (const CreateStmt *) node);
 
        WRITE_STRING_FIELD(servername);
        WRITE_NODE_FIELD(options);
@@ -1965,6 +2010,7 @@ _outIndexStmt(StringInfo str, const IndexStmt *node)
        WRITE_NODE_FIELD(options);
        WRITE_NODE_FIELD(whereClause);
        WRITE_NODE_FIELD(excludeOpNames);
+       WRITE_STRING_FIELD(idxcomment);
        WRITE_OID_FIELD(indexOid);
        WRITE_OID_FIELD(oldNode);
        WRITE_BOOL_FIELD(unique);
@@ -2007,12 +2053,12 @@ _outSelectStmt(StringInfo str, const SelectStmt *node)
        WRITE_NODE_FIELD(groupClause);
        WRITE_NODE_FIELD(havingClause);
        WRITE_NODE_FIELD(windowClause);
-       WRITE_NODE_FIELD(withClause);
        WRITE_NODE_FIELD(valuesLists);
        WRITE_NODE_FIELD(sortClause);
        WRITE_NODE_FIELD(limitOffset);
        WRITE_NODE_FIELD(limitCount);
        WRITE_NODE_FIELD(lockingClause);
+       WRITE_NODE_FIELD(withClause);
        WRITE_ENUM_FIELD(op, SetOperation);
        WRITE_BOOL_FIELD(all);
        WRITE_NODE_FIELD(larg);
@@ -2086,7 +2132,7 @@ _outColumnDef(StringInfo str, const ColumnDef *node)
        WRITE_BOOL_FIELD(is_local);
        WRITE_BOOL_FIELD(is_not_null);
        WRITE_BOOL_FIELD(is_from_type);
-       WRITE_INT_FIELD(storage);
+       WRITE_CHAR_FIELD(storage);
        WRITE_NODE_FIELD(raw_default);
        WRITE_NODE_FIELD(cooked_default);
        WRITE_NODE_FIELD(collClause);
@@ -2151,6 +2197,7 @@ _outQuery(StringInfo str, const Query *node)
 
        WRITE_ENUM_FIELD(commandType, CmdType);
        WRITE_ENUM_FIELD(querySource, QuerySource);
+       /* we intentionally do not print the queryId field */
        WRITE_BOOL_FIELD(canSetTag);
 
        /*
@@ -2179,7 +2226,6 @@ _outQuery(StringInfo str, const Query *node)
                appendStringInfo(str, " :utilityStmt <>");
 
        WRITE_INT_FIELD(resultRelation);
-       WRITE_NODE_FIELD(intoClause);
        WRITE_BOOL_FIELD(hasAggs);
        WRITE_BOOL_FIELD(hasWindowFuncs);
        WRITE_BOOL_FIELD(hasSubLinks);
@@ -2332,6 +2378,7 @@ _outRangeTblEntry(StringInfo str, const RangeTblEntry *node)
                        break;
        }
 
+       WRITE_BOOL_FIELD(lateral);
        WRITE_BOOL_FIELD(inh);
        WRITE_BOOL_FIELD(inFromCl);
        WRITE_UINT_FIELD(requiredPerms);
@@ -2535,6 +2582,7 @@ _outRangeSubselect(StringInfo str, const RangeSubselect *node)
 {
        WRITE_NODE_TYPE("RANGESUBSELECT");
 
+       WRITE_BOOL_FIELD(lateral);
        WRITE_NODE_FIELD(subquery);
        WRITE_NODE_FIELD(alias);
 }
@@ -2544,6 +2592,7 @@ _outRangeFunction(StringInfo str, const RangeFunction *node)
 {
        WRITE_NODE_TYPE("RANGEFUNCTION");
 
+       WRITE_BOOL_FIELD(lateral);
        WRITE_NODE_FIELD(funccallnode);
        WRITE_NODE_FIELD(alias);
        WRITE_NODE_FIELD(coldeflist);
@@ -2578,6 +2627,7 @@ _outConstraint(StringInfo str, const Constraint *node)
 
                case CONSTR_CHECK:
                        appendStringInfo(str, "CHECK");
+                       WRITE_BOOL_FIELD(is_no_inherit);
                        WRITE_NODE_FIELD(raw_expr);
                        WRITE_STRING_FIELD(cooked_expr);
                        break;
@@ -2990,6 +3040,9 @@ _outNode(StringInfo str, const void *obj)
                        case T_PathKey:
                                _outPathKey(str, obj);
                                break;
+                       case T_ParamPathInfo:
+                               _outParamPathInfo(str, obj);
+                               break;
                        case T_RestrictInfo:
                                _outRestrictInfo(str, obj);
                                break;
@@ -2999,6 +3052,9 @@ _outNode(StringInfo str, const void *obj)
                        case T_SpecialJoinInfo:
                                _outSpecialJoinInfo(str, obj);
                                break;
+                       case T_LateralJoinInfo:
+                               _outLateralJoinInfo(str, obj);
+                               break;
                        case T_AppendRelInfo:
                                _outAppendRelInfo(str, obj);
                                break;