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 a51fc34e6e0..775955363ef 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -695,6 +695,7 @@ infer_arbiter_indexes(PlannerInfo *root) OnConflictExpr *onconflict = root->parse->onConflict; /* Iteration state */ + Index varno; RangeTblEntry *rte; Relation relation; Oid indexOidFromConstraint = InvalidOid; @@ -723,7 +724,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); @@ -857,6 +859,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); @@ -908,6 +913,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; |