pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
ERROR: tuple to be updated was already modified by an operation triggered by the current command
4+ messages / 3 participants
[nested] [flat]

* ERROR: tuple to be updated was already modified by an operation triggered by the current command
@ 2025-01-23 09:11  Richard Guo <guofenglinux@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Richard Guo @ 2025-01-23 09:11 UTC (permalink / raw)
  To: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

I came across $SUBJECT, which can be reproduced using the queries
below.

# create temporary table p (a int primary key) on commit delete rows;
CREATE TABLE
# create temporary table c () inherits (p);
CREATE TABLE

# analyze; -- no error
ANALYZE

# drop table c;
DROP TABLE

# analyze; -- error
ERROR:  tuple to be updated was already modified by an operation
triggered by the current command

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

a07e03fd8fa7daf4d1356f7cb501ffe784ea6257 is the first bad commit
commit a07e03fd8fa7daf4d1356f7cb501ffe784ea6257
Author: Noah Misch <noah@leadboat.com>
Date:   Tue Sep 24 15:25:18 2024 -0700

    Fix data loss at inplace update after heap_update().

... which introduced heap_inplace_lock().

Is this error expected, or could it be a bug?

Thanks
Richard





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: ERROR: tuple to be updated was already modified by an operation triggered by the current command
@ 2025-04-11 12:48  Robins Tharakan <tharakan@gmail.com>
  parent: Richard Guo <guofenglinux@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Robins Tharakan @ 2025-04-11 12:48 UTC (permalink / raw)
  To: Richard Guo <guofenglinux@gmail.com>; +Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>; noah@leadboat.com

Hi,

On Thu, 23 Jan 2025 at 19:42, Richard Guo <guofenglinux@gmail.com> wrote:
>
> I came across $SUBJECT, which can be reproduced using the queries
> below.

I also stepped a few times on this the past few days. Here's a smaller
repro:

$ grep -l -B100 "tuple to be updated was already modified by an operation
triggered by the current command" */source | xargs -i grep Assertion {}
--java.lang.AssertionError: ANALYZE;
--java.lang.AssertionError: ANALYZE( SKIP_LOCKED);
--java.lang.AssertionError: ANALYZE;
--java.lang.AssertionError: ANALYZE( VERBOSE);
--java.lang.AssertionError: ANALYZE( VERBOSE);


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


SQL Output
==========
$ psql postgres -f a.sql
CREATE TABLE
CREATE TABLE
psql:a.sql:6: ERROR:  tuple to be updated was already modified by an
operation triggered by the current command



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


I also arrived at the same commit.

Checking (914ea1c93c0~0) - 914ea1c93c - fail (1)
Checking (914ea1c93c0~10) - d89335eea6 - fail (1)
Checking (914ea1c93c0~30) - b0a4c3e88b - fail (1)
Checking (914ea1c93c0~70) - 57dec20fd4 - fail (1)
.
.
Checking (914ea1c93c0~1688) - a07e03fd8f - fail (1)
Checking (914ea1c93c0~1689) - dbf3f974ee - pass (0)
Surfacing Commit is a07e03fd8fa7daf4d1356f7cb501ffe784ea6257


Found using SQLancer / creduce.
-
robins
https://robins.in

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: ERROR: tuple to be updated was already modified by an operation triggered by the current command
@ 2025-04-11 14:41  Noah Misch <noah@leadboat.com>
  parent: Robins Tharakan <tharakan@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Noah Misch @ 2025-04-11 14:41 UTC (permalink / raw)
  To: Robins Tharakan <tharakan@gmail.com>; +Cc: Richard Guo <guofenglinux@gmail.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

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.





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: ERROR: tuple to be updated was already modified by an operation triggered by the current command
@ 2025-04-21 04:06  Noah Misch <noah@leadboat.com>
  parent: Noah Misch <noah@leadboat.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Noah Misch @ 2025-04-21 04:06 UTC (permalink / raw)
  To: Robins Tharakan <tharakan@gmail.com>; +Cc: Richard Guo <guofenglinux@gmail.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On Fri, Apr 11, 2025 at 07:41:33AM -0700, Noah Misch wrote:
> 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;

> --- 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();

Pushed: postgr.es/c/2d5350c





^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2025-04-21 04:06 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-01-23 09:11 ERROR: tuple to be updated was already modified by an operation triggered by the current command Richard Guo <guofenglinux@gmail.com>
2025-04-11 12:48 ` Robins Tharakan <tharakan@gmail.com>
2025-04-11 14:41   ` Noah Misch <noah@leadboat.com>
2025-04-21 04:06     ` Noah Misch <noah@leadboat.com>

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