pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Noah Misch <noah@leadboat.com>
To: Robins Tharakan <tharakan@gmail.com>
Cc: Richard Guo <guofenglinux@gmail.com>
Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Subject: Re: ERROR: tuple to be updated was already modified by an operation triggered by the current command
Date: Fri, 11 Apr 2025 07:41:33 -0700
Message-ID: <20250411144133.d5.nmisch@google.com> (raw)
In-Reply-To: <CAEP4nAy1BT52u=yf+GKGgbDMAR3re6mM992DXaaoaZq1XQ5a1Q@mail.gmail.com>
References: <CAMbWs4-XwMKMKJ_GT=p3_-_=j9rQSEs1FbDFUnW9zHuKPsPNEQ@mail.gmail.com>
	<CAEP4nAy1BT52u=yf+GKGgbDMAR3re6mM992DXaaoaZq1XQ5a1Q@mail.gmail.com>

On Fri, Apr 11, 2025 at 10:18:04PM +0930, Robins Tharakan wrote:
> On Thu, 23 Jan 2025 at 19:42, Richard Guo <guofenglinux@gmail.com> wrote:

> Repro SQL
> =========
> CREATE TEMPORARY TABLE a(b boolean , UNIQUE(b)) ON COMMIT DELETE ROWS ;
> CREATE TEMP TABLE d() INHERITS(a) ON COMMIT DROP ;
> ANALYSE;

Confirmed.  Thanks for the report.  This is a variant of the bug that commit
7102070 fixed.  Key events:

- The second CREATE sets relhassubclass=t on "a".
- ANALYZE does heap_update() to set relhassubclass=f, since ON COMMIT DROP
  removed the child.
- ON COMMIT DELETE ROWS does an empty index build at end-of-xact, which does
  an inplace update on the pg_class row of "a".  There was no
  CommandCounterIncrement() since the heap_update(), hence this error.

Changing to "ANALYSE a" makes the error go away, because
standard_ProcessUtility() does a CCI (added for bug #15631).  So I'm inclined
to fix that by putting the CCI here for plain "ANALYSE":

--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -657,6 +657,8 @@ vacuum(List *relations, VacuumParams *params, BufferAccessStrategy bstrategy,
 				if (use_own_xacts)
 				{
 					PopActiveSnapshot();
+					/* standard_ProcessUtility() does CCI if !use_own_xacts */
+					CommandCounterIncrement();
 					CommitTransactionCommand();
 				}
 				else

> > This error happens in heap_inplace_lock(), and git-bisect says the
> > first bad commit is:
> >
> > a07e03fd8fa7daf4d1356f7cb501ffe784ea6257 is the first bad commit

That commit made it an error to inplace-update an invisible tuple; before
that, we silently lost the inplace update.





view thread (4+ messages)  latest in thread

Message-ID: <20250411144133.d5.nmisch@google.com>
Permalink:  ../20250411144133.d5.nmisch@google.com/
Also on:    postgresql.org/message-id/20250411144133.d5.nmisch@google.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noah@leadboat.com, tharakan@gmail.com, guofenglinux@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: ERROR: tuple to be updated was already modified by an operation triggered by the current command
  In-Reply-To: <20250411144133.d5.nmisch@google.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox