| From: | Amit Langote <amitlangote09(at)gmail(dot)com> |
|---|---|
| To: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: stale comment about locking in ExecInitModifyTable() |
| Date: | 2026-12-02 06:22:13 |
| Message-ID: | CA+HiwqHOjB0JJT_5+Yvx=ZoV4xmFCTF0AB4Qh2Awv5iHfb=mqg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
On Tue, Dec 1, 2026 at 2:17 PM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
> > On Dec 1, 2026, at 10:52, Amit Langote <amitlangote09(at)gmail(dot)com> wrote:
> >
> > Subject: Remove stale comment about locking in ExecInitModifyTable()
> >
> > Hi,
> >
> > While looking at ExecInitModifyTable() for another patch, I noticed
> > that a comment there still says that ExecDoInitialPruning() takes care
> > of locking the first result relation:
> >
> > * In either case, it doesn't matter which result relation is kept, so we
> > * just keep the first one, if all others have been pruned. See also,
> > * ExecDoInitialPruning(), which ensures that this first result relation
> > * has been locked.
> >
> > That sentence came in with my 28317de723, along with the code in
> > ExecDoInitialPruning() that it refers to, which locked the first
> > result relation of each ModifyTable node. 1722d5eb05 (mine too)
> > removed that code but left the sentence behind.
> >
> > The attached patch removes it. I'm inclined to back-patch this to v18,
> > where the sentence first appeared.
>
> I checked both 28317de723 and 1722d5eb05.
>
> Looks like 1722d5eb05 partially reverted 28317de723. The changes in nodeModifyTable.c were retained. This patch removes a sentence from a comment in nodeModifyTable.c:
> ```
> * See also,
> * ExecDoInitialPruning(), which ensures that this first result relation
> * has been locked.
> ```
>
> If I understand correctly, it's related to the following code reverted in ExecDoInitialPruning(), which is defined in execPartition.c:
> ```
> -
> - /*
> - * Lock the first result relation of each ModifyTable node, even if it was
> - * pruned. This is required for ExecInitModifyTable(), which keeps its
> - * first result relation if all other result relations have been pruned,
> - * because some executor paths (e.g., in nodeModifyTable.c and
> - * execPartition.c) rely on there being at least one result relation.
> - *
> - * There's room for improvement here --- we actually only need to do this
> - * if all other result relations of the ModifyTable node were pruned, but
> - * we don't have an easy way to tell that here.
> - */
> - if (stmt->resultRelations && ExecShouldLockRelations(estate))
> - {
> - foreach(lc, stmt->firstResultRels)
> - {
> - Index firstResultRel = lfirst_int(lc);
> -
> - if (!bms_is_member(firstResultRel, estate->es_unpruned_relids))
> - {
> - RangeTblEntry *rte = exec_rt_fetch(firstResultRel, estate);
> -
> - Assert(rte->rtekind == RTE_RELATION && rte->rellockmode != NoLock);
> - LockRelationOid(rte->relid, rte->rellockmode);
> - locked_relids = lappend_int(locked_relids, firstResultRel);
> - }
> - }
> - }
> ```
Your understanding is correct.
> So, v1 looks good to me.
Pushed, thanks for checking.
--
Thanks, Amit Langote
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Hüseyin Demir | 2026-12-02 06:25:12 | Re: [PATCH] Report changes discarded for relations not in the subscription |
| Previous Message | Tristan Su | 2026-12-02 06:21:22 | [PATCH v2] Reuse slot helpers in pg_get_replication_slots and slot copy |