diff options
Diffstat (limited to 'src/backend/optimizer/util/plancat.c')
-rw-r--r-- | src/backend/optimizer/util/plancat.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index 39932d3c2d2..07c4ba384ab 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -667,6 +667,7 @@ infer_arbiter_indexes(PlannerInfo *root) OnConflictExpr *onconflict = root->parse->onConflict; /* Iteration state */ + Index varno; RangeTblEntry *rte; Relation relation; Oid indexOidFromConstraint = InvalidOid; @@ -695,7 +696,8 @@ infer_arbiter_indexes(PlannerInfo *root) * the rewriter or when expand_inherited_rtentry() added it to the query's * rangetable. */ - rte = rt_fetch(root->parse->resultRelation, root->parse->rtable); + varno = root->parse->resultRelation; + rte = rt_fetch(varno, root->parse->rtable); relation = table_open(rte->relid, NoLock); @@ -829,6 +831,9 @@ infer_arbiter_indexes(PlannerInfo *root) /* Expression attributes (if any) must match */ idxExprs = RelationGetIndexExpressions(idxRel); + if (idxExprs && varno != 1) + ChangeVarNodes((Node *) idxExprs, 1, varno, 0); + foreach(el, onconflict->arbiterElems) { InferenceElem *elem = (InferenceElem *) lfirst(el); @@ -880,6 +885,8 @@ infer_arbiter_indexes(PlannerInfo *root) * CONFLICT's WHERE clause. */ predExprs = RelationGetIndexPredicate(idxRel); + if (predExprs && varno != 1) + ChangeVarNodes((Node *) predExprs, 1, varno, 0); if (!predicate_implied_by(predExprs, (List *) onconflict->arbiterWhere, false)) goto next; |