On 2015-08-05 AM 06:44, Peter Geoghegan wrote: > On Tue, Aug 4, 2015 at 2:29 AM, Amit Langote > <langote_amit...@lab.ntt.co.jp> wrote: >> Perhaps, it may have to do with how EXCLUDED pseudo-rel's targetlist is >> manipulated through parse-plan stage? > > I think so, yes. > > I'll look into writing a fix for this later in the week. >
Just a heads-up. I forgot mentioning one thing later yesterday. The way exclRelTlist is initialized, all the way in the beginning (transformOnConflictClause), is most probably to blame. It uses expandRelAttrs() for other valid reasons; but within it, expandRTE() is called with 'false' for include_dropped (columns). I applied the attached (perhaps ugly) fix, and it seemed to fix the issue. But, I guess you'll be able to come up with some better fix. Thanks, Amit
diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index a0dfbf9..cd67c96 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -915,7 +915,7 @@ transformOnConflictClause(ParseState *pstate, * required permissions back. */ exclRelTlist = expandRelAttrs(pstate, exclRte, - exclRelIndex, 0, -1); + exclRelIndex, 0, -1, true); exclRte->requiredPerms = 0; exclRte->selectedCols = NULL; @@ -1312,7 +1312,7 @@ transformValuesClause(ParseState *pstate, SelectStmt *stmt) * Generate a targetlist as though expanding "*" */ Assert(pstate->p_next_resno == 1); - qry->targetList = expandRelAttrs(pstate, rte, rtindex, 0, -1); + qry->targetList = expandRelAttrs(pstate, rte, rtindex, 0, -1, false); /* * The grammar allows attaching ORDER BY, LIMIT, and FOR UPDATE to a diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c index 0b2dacf..98124e4 100644 --- a/src/backend/parser/parse_relation.c +++ b/src/backend/parser/parse_relation.c @@ -2418,7 +2418,8 @@ expandTupleDesc(TupleDesc tupdesc, Alias *eref, int count, int offset, */ List * expandRelAttrs(ParseState *pstate, RangeTblEntry *rte, - int rtindex, int sublevels_up, int location) + int rtindex, int sublevels_up, int location, + bool include_dropped_cols) { List *names, *vars; @@ -2426,7 +2427,7 @@ expandRelAttrs(ParseState *pstate, RangeTblEntry *rte, *var; List *te_list = NIL; - expandRTE(rte, rtindex, sublevels_up, location, false, + expandRTE(rte, rtindex, sublevels_up, location, include_dropped_cols, &names, &vars); /* @@ -2448,6 +2449,10 @@ expandRelAttrs(ParseState *pstate, RangeTblEntry *rte, false); te_list = lappend(te_list, te); + /* Dropped columns ain't Vars */ + if (!IsA(varnode, Var)) + continue; + /* Require read access to each column */ markVarForSelectPriv(pstate, varnode, rte); } diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c index 1b3fcd6..6712464 100644 --- a/src/backend/parser/parse_target.c +++ b/src/backend/parser/parse_target.c @@ -1185,7 +1185,7 @@ ExpandAllTables(ParseState *pstate, int location) RTERangeTablePosn(pstate, rte, NULL), 0, - location)); + location, false)); } /* @@ -1253,7 +1253,7 @@ ExpandSingleTable(ParseState *pstate, RangeTblEntry *rte, { /* expandRelAttrs handles permissions marking */ return expandRelAttrs(pstate, rte, rtindex, sublevels_up, - location); + location, false); } else { diff --git a/src/include/parser/parse_relation.h b/src/include/parser/parse_relation.h index e2875a0..591e049 100644 --- a/src/include/parser/parse_relation.h +++ b/src/include/parser/parse_relation.h @@ -110,8 +110,8 @@ extern void errorMissingColumn(ParseState *pstate, extern void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, int location, bool include_dropped, List **colnames, List **colvars); -extern List *expandRelAttrs(ParseState *pstate, RangeTblEntry *rte, - int rtindex, int sublevels_up, int location); +extern List *expandRelAttrs(ParseState *pstate, RangeTblEntry *rte, int rtindex, + int sublevels_up, int location, bool include_dropped_cols); extern int attnameAttNum(Relation rd, const char *attname, bool sysColOK); extern Name attnumAttName(Relation rd, int attid); extern Oid attnumTypeId(Relation rd, int attid);
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers