=== Applying patches on top of PostgreSQL commit ID 2047ad068139f0b8c6da73d0b845ca9ba30fb33d === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Wed Jul 23 18:35:20 UTC 2025 On branch cf/5854 nothing to commit, working tree clean === using 'git am' to apply patch ./v3-0001-Allow-EXCLUDED-in-RETURNING-list-of-INSERT-ON-CON.patch === Applying: Allow EXCLUDED in RETURNING list of INSERT ON CONFLICT DO UPDATE. Using index info to reconstruct a base tree... M src/backend/executor/execExprInterp.c M src/backend/executor/nodeModifyTable.c M src/backend/optimizer/prep/prepjointree.c M src/backend/optimizer/util/clauses.c M src/test/regress/expected/generated_virtual.out M src/test/regress/expected/rules.out M src/test/regress/sql/generated_virtual.sql M src/tools/pgindent/typedefs.list Falling back to patching base and 3-way merge... Auto-merging src/tools/pgindent/typedefs.list Auto-merging src/test/regress/sql/generated_virtual.sql Auto-merging src/test/regress/expected/rules.out Auto-merging src/test/regress/expected/generated_virtual.out Auto-merging src/backend/optimizer/util/clauses.c Auto-merging src/backend/optimizer/prep/prepjointree.c CONFLICT (content): Merge conflict in src/backend/optimizer/prep/prepjointree.c Auto-merging src/backend/executor/nodeModifyTable.c Auto-merging src/backend/executor/execExprInterp.c error: Failed to merge in the changes. hint: Use 'git am --show-current-patch=diff' to see the failed patch Patch failed at 0001 Allow EXCLUDED in RETURNING list of INSERT ON CONFLICT DO UPDATE. When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". Unstaged changes after reset: M doc/src/sgml/dml.sgml M doc/src/sgml/ref/insert.sgml M src/backend/executor/execExpr.c M src/backend/executor/execExprInterp.c M src/backend/executor/execPartition.c M src/backend/executor/nodeModifyTable.c M src/backend/optimizer/path/allpaths.c M src/backend/optimizer/plan/setrefs.c M src/backend/optimizer/prep/prepjointree.c M src/backend/optimizer/prep/preptlist.c M src/backend/optimizer/util/clauses.c M src/backend/optimizer/util/var.c M src/backend/parser/analyze.c M src/backend/parser/parse_expr.c M src/backend/parser/parse_relation.c M src/backend/rewrite/rewriteHandler.c M src/backend/rewrite/rewriteManip.c M src/include/executor/execExpr.h M src/include/nodes/execnodes.h M src/include/nodes/primnodes.h M src/include/parser/parse_node.h M src/include/rewrite/rewriteManip.h M src/test/regress/expected/arrays.out M src/test/regress/expected/generated_stored.out M src/test/regress/expected/generated_virtual.out M src/test/regress/expected/inherit.out M src/test/regress/expected/insert_conflict.out M src/test/regress/expected/returning.out M src/test/regress/expected/rules.out M src/test/regress/expected/triggers.out M src/test/regress/expected/updatable_views.out M src/test/regress/sql/arrays.sql M src/test/regress/sql/generated_stored.sql M src/test/regress/sql/generated_virtual.sql M src/test/regress/sql/inherit.sql M src/test/regress/sql/insert_conflict.sql M src/test/regress/sql/returning.sql M src/test/regress/sql/rules.sql M src/test/regress/sql/triggers.sql M src/test/regress/sql/updatable_views.sql M src/tools/pgindent/typedefs.list === using patch(1) to apply patch ./v3-0001-Allow-EXCLUDED-in-RETURNING-list-of-INSERT-ON-CON.patch === patching file doc/src/sgml/dml.sgml patching file doc/src/sgml/ref/insert.sgml patching file src/backend/executor/execExpr.c patching file src/backend/executor/execExprInterp.c Hunk #1 succeeded at 5339 (offset -1 lines). Hunk #2 succeeded at 5398 (offset -1 lines). patching file src/backend/executor/execPartition.c patching file src/backend/executor/nodeModifyTable.c Hunk #6 succeeded at 1908 (offset 1 line). Hunk #7 succeeded at 2468 (offset 2 lines). Hunk #8 succeeded at 2479 (offset 2 lines). Hunk #9 succeeded at 2712 (offset 2 lines). Hunk #10 succeeded at 2935 (offset 2 lines). Hunk #11 succeeded at 3560 (offset 2 lines). Hunk #12 succeeded at 3570 (offset 2 lines). Hunk #13 succeeded at 4335 (offset 2 lines). Hunk #14 succeeded at 4534 (offset 2 lines). patching file src/backend/optimizer/path/allpaths.c patching file src/backend/optimizer/plan/setrefs.c patching file src/backend/optimizer/prep/prepjointree.c Hunk #1 succeeded at 72 (offset 1 line). Hunk #2 FAILED at 1033. Hunk #3 succeeded at 1495 (offset 60 lines). Hunk #4 succeeded at 2046 (offset 60 lines). Hunk #5 succeeded at 2206 (offset 60 lines). Hunk #6 succeeded at 2740 (offset 60 lines). 1 out of 6 hunks FAILED -- saving rejects to file src/backend/optimizer/prep/prepjointree.c.rej patching file src/backend/optimizer/prep/preptlist.c patching file src/backend/optimizer/util/clauses.c Hunk #1 succeeded at 3418 (offset 4 lines). patching file src/backend/optimizer/util/var.c patching file src/backend/parser/analyze.c patching file src/backend/parser/parse_expr.c patching file src/backend/parser/parse_relation.c patching file src/backend/rewrite/rewriteHandler.c patching file src/backend/rewrite/rewriteManip.c patching file src/include/executor/execExpr.h patching file src/include/nodes/execnodes.h patching file src/include/nodes/primnodes.h patching file src/include/parser/parse_node.h patching file src/include/rewrite/rewriteManip.h patching file src/test/regress/expected/arrays.out patching file src/test/regress/expected/generated_stored.out patching file src/test/regress/expected/generated_virtual.out patching file src/test/regress/expected/inherit.out patching file src/test/regress/expected/insert_conflict.out patching file src/test/regress/expected/returning.out patching file src/test/regress/expected/rules.out Hunk #1 succeeded at 3531 (offset 4 lines). patching file src/test/regress/expected/triggers.out patching file src/test/regress/expected/updatable_views.out patching file src/test/regress/sql/arrays.sql patching file src/test/regress/sql/generated_stored.sql patching file src/test/regress/sql/generated_virtual.sql patching file src/test/regress/sql/inherit.sql patching file src/test/regress/sql/insert_conflict.sql patching file src/test/regress/sql/returning.sql patching file src/test/regress/sql/rules.sql patching file src/test/regress/sql/triggers.sql patching file src/test/regress/sql/updatable_views.sql patching file src/tools/pgindent/typedefs.list Hunk #1 succeeded at 2572 (offset 3 lines). Unstaged changes after reset: M doc/src/sgml/dml.sgml M doc/src/sgml/ref/insert.sgml M src/backend/executor/execExpr.c M src/backend/executor/execExprInterp.c M src/backend/executor/execPartition.c M src/backend/executor/nodeModifyTable.c M src/backend/optimizer/path/allpaths.c M src/backend/optimizer/plan/setrefs.c M src/backend/optimizer/prep/prepjointree.c M src/backend/optimizer/prep/preptlist.c M src/backend/optimizer/util/clauses.c M src/backend/optimizer/util/var.c M src/backend/parser/analyze.c M src/backend/parser/parse_expr.c M src/backend/parser/parse_relation.c M src/backend/rewrite/rewriteHandler.c M src/backend/rewrite/rewriteManip.c M src/include/executor/execExpr.h M src/include/nodes/execnodes.h M src/include/nodes/primnodes.h M src/include/parser/parse_node.h M src/include/rewrite/rewriteManip.h M src/test/regress/expected/arrays.out M src/test/regress/expected/generated_stored.out M src/test/regress/expected/generated_virtual.out M src/test/regress/expected/inherit.out M src/test/regress/expected/insert_conflict.out M src/test/regress/expected/returning.out M src/test/regress/expected/rules.out M src/test/regress/expected/triggers.out M src/test/regress/expected/updatable_views.out M src/test/regress/sql/arrays.sql M src/test/regress/sql/generated_stored.sql M src/test/regress/sql/generated_virtual.sql M src/test/regress/sql/inherit.sql M src/test/regress/sql/insert_conflict.sql M src/test/regress/sql/returning.sql M src/test/regress/sql/rules.sql M src/test/regress/sql/triggers.sql M src/test/regress/sql/updatable_views.sql M src/tools/pgindent/typedefs.list Removing src/backend/optimizer/prep/prepjointree.c.rej === using 'git apply' to apply patch ./v3-0001-Allow-EXCLUDED-in-RETURNING-list-of-INSERT-ON-CON.patch === Applied patch to 'doc/src/sgml/dml.sgml' cleanly. Applied patch to 'doc/src/sgml/ref/insert.sgml' cleanly. Applied patch to 'src/backend/executor/execExpr.c' cleanly. Applied patch to 'src/backend/executor/execExprInterp.c' cleanly. Applied patch to 'src/backend/executor/execPartition.c' cleanly. Applied patch to 'src/backend/executor/nodeModifyTable.c' cleanly. Applied patch to 'src/backend/optimizer/path/allpaths.c' cleanly. Applied patch to 'src/backend/optimizer/plan/setrefs.c' cleanly. Applied patch to 'src/backend/optimizer/prep/prepjointree.c' with conflicts. Applied patch to 'src/backend/optimizer/prep/preptlist.c' cleanly. Applied patch to 'src/backend/optimizer/util/clauses.c' cleanly. Applied patch to 'src/backend/optimizer/util/var.c' cleanly. Applied patch to 'src/backend/parser/analyze.c' cleanly. Applied patch to 'src/backend/parser/parse_expr.c' cleanly. Applied patch to 'src/backend/parser/parse_relation.c' cleanly. Applied patch to 'src/backend/rewrite/rewriteHandler.c' cleanly. Applied patch to 'src/backend/rewrite/rewriteManip.c' cleanly. Applied patch to 'src/include/executor/execExpr.h' cleanly. Applied patch to 'src/include/nodes/execnodes.h' cleanly. Applied patch to 'src/include/nodes/primnodes.h' cleanly. Applied patch to 'src/include/parser/parse_node.h' cleanly. Applied patch to 'src/include/rewrite/rewriteManip.h' cleanly. Applied patch to 'src/test/regress/expected/arrays.out' cleanly. Applied patch to 'src/test/regress/expected/generated_stored.out' cleanly. Applied patch to 'src/test/regress/expected/generated_virtual.out' cleanly. Applied patch to 'src/test/regress/expected/inherit.out' cleanly. Applied patch to 'src/test/regress/expected/insert_conflict.out' cleanly. Applied patch to 'src/test/regress/expected/returning.out' cleanly. Applied patch to 'src/test/regress/expected/rules.out' cleanly. Applied patch to 'src/test/regress/expected/triggers.out' cleanly. Applied patch to 'src/test/regress/expected/updatable_views.out' cleanly. Applied patch to 'src/test/regress/sql/arrays.sql' cleanly. Applied patch to 'src/test/regress/sql/generated_stored.sql' cleanly. Applied patch to 'src/test/regress/sql/generated_virtual.sql' cleanly. Applied patch to 'src/test/regress/sql/inherit.sql' cleanly. Applied patch to 'src/test/regress/sql/insert_conflict.sql' cleanly. Applied patch to 'src/test/regress/sql/returning.sql' cleanly. Applied patch to 'src/test/regress/sql/rules.sql' cleanly. Applied patch to 'src/test/regress/sql/triggers.sql' cleanly. Applied patch to 'src/test/regress/sql/updatable_views.sql' cleanly. Applied patch to 'src/tools/pgindent/typedefs.list' cleanly. U src/backend/optimizer/prep/prepjointree.c diff --cc src/backend/optimizer/prep/prepjointree.c index 35e8d3c183b,00de20b0d49..00000000000 --- a/src/backend/optimizer/prep/prepjointree.c +++ b/src/backend/optimizer/prep/prepjointree.c @@@ -1129,6 -949,136 +1128,139 @@@ preprocess_function_rtes(PlannerInfo *r } /* ++<<<<<<< ours ++======= + * expand_virtual_generated_columns + * Expand all virtual generated column references in a query. + * + * This scans the rangetable for relations with virtual generated columns, and + * replaces all Var nodes in the query that reference these columns with the + * generation expressions. Note that we do not descend into subqueries; that + * is taken care of when the subqueries are planned. + * + * This has to be done after we have pulled up any SubLinks within the query's + * quals; otherwise any virtual generated column references within the SubLinks + * that should be transformed into joins wouldn't get expanded. + * + * Returns a modified copy of the query tree, if any relations with virtual + * generated columns are present. + */ + Query * + expand_virtual_generated_columns(PlannerInfo *root) + { + Query *parse = root->parse; + int rt_index; + ListCell *lc; + + rt_index = 0; + foreach(lc, parse->rtable) + { + RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc); + Relation rel; + TupleDesc tupdesc; + + ++rt_index; + + /* + * Only normal relations can have virtual generated columns. + */ + if (rte->rtekind != RTE_RELATION) + continue; + + rel = table_open(rte->relid, NoLock); + + tupdesc = RelationGetDescr(rel); + if (tupdesc->constr && tupdesc->constr->has_generated_virtual) + { + List *tlist = NIL; + pullup_replace_vars_context rvcontext; + + for (int i = 0; i < tupdesc->natts; i++) + { + Form_pg_attribute attr = TupleDescAttr(tupdesc, i); + TargetEntry *tle; + + if (attr->attgenerated == ATTRIBUTE_GENERATED_VIRTUAL) + { + Node *defexpr; + + defexpr = build_generation_expression(rel, i + 1); + ChangeVarNodes(defexpr, 1, rt_index, 0); + + tle = makeTargetEntry((Expr *) defexpr, i + 1, 0, false); + tlist = lappend(tlist, tle); + } + else + { + Var *var; + + var = makeVar(rt_index, + i + 1, + attr->atttypid, + attr->atttypmod, + attr->attcollation, + 0); + + tle = makeTargetEntry((Expr *) var, i + 1, 0, false); + tlist = lappend(tlist, tle); + } + } + + Assert(list_length(tlist) > 0); + Assert(!rte->lateral); + + /* + * The relation's targetlist items are now in the appropriate form + * to insert into the query, except that we may need to wrap them + * in PlaceHolderVars. Set up required context data for + * pullup_replace_vars. + * + * new_target_varno should equal rt_index if this is the result + * relation or the EXCLUDED pseudo-relation. Otherwise, it should + * be 0. See comments in ReplaceVarFromTargetList(). + */ + rvcontext.root = root; + rvcontext.targetlist = tlist; + rvcontext.target_rte = rte; + if (rt_index == parse->resultRelation || + (parse->onConflict && rt_index == parse->onConflict->exclRelIndex)) + rvcontext.new_target_varno = rt_index; + else + rvcontext.new_target_varno = 0; + /* won't need these values */ + rvcontext.relids = NULL; + rvcontext.nullinfo = NULL; + /* pass NULL for outer_hasSubLinks */ + rvcontext.outer_hasSubLinks = NULL; + rvcontext.varno = rt_index; + /* this flag will be set below, if needed */ + rvcontext.wrap_option = REPLACE_WRAP_NONE; + /* initialize cache array with indexes 0 .. length(tlist) */ + rvcontext.rv_cache = palloc0((list_length(tlist) + 1) * + sizeof(Node *)); + + /* + * If the query uses grouping sets, we need a PlaceHolderVar for + * each expression of the relation's targetlist items. (See + * comments in pull_up_simple_subquery().) + */ + if (parse->groupingSets) + rvcontext.wrap_option = REPLACE_WRAP_ALL; + + /* + * Apply pullup variable replacement throughout the query tree. + */ + parse = (Query *) pullup_replace_vars((Node *) parse, &rvcontext); + } + + table_close(rel, NoLock); + } + + return parse; + } + + /* ++>>>>>>> theirs * pull_up_subqueries * Look for subqueries in the rangetable that can be pulled up into * the parent query. If the subquery has no special features like