Re: Assert when executing query on partitioned table

From: Dmitry Koval <d(dot)koval(at)postgrespro(dot)ru>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Assert when executing query on partitioned table
Date: 2025-12-18 23:27:34
Message-ID: ddebf313-54b4-4bf9-851d-c770e33e768a@postgrespro.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi!

Unfortunately, the issue is still relevant, so I'm updating the first
post and patches. I got an Assert when executing an "INSERT ... ON
CONFLICT ... UPDATE ..." query on partitioned table.

Reproduction order.
-------------------

1) Apply the patch
[v1-0001-Triggering-Assert-on-query-with-ON-CONFLICT.no_cfbot]
to "master" branch:

git am v1-0001-Triggering-Assert-on-query-with-ON-CONFLICT.no_cfbot

2) Build postgres with "--enable-injection-points --enable-cassert",
for example:

./configure --enable-injection-points --enable-debug --enable-cassert
>/dev/null && make -j4 -s

3) Run isolation test onconflict.spec:

make check -C src/test/modules/injection_points

Assert is triggered in postgres, with part of stack:
...
#3 0x0000624cb170e05f in ExceptionalCondition (
conditionName=conditionName(at)entry=0x624cb17fcbf0
"!ItemPointerIndicatesMovedPartitions(&tmfd.ctid)",
fileName=fileName(at)entry=0x624cb1785ea7 "nodeModifyTable.c",
lineNumber=lineNumber(at)entry=2819) at assert.c:65
#4 0x0000624cb13f1412 in ExecOnConflictUpdate (returning=<synthetic
pointer>, canSetTag=true, excludedSlot=0x624cb2a61750,
conflictTid=0x7fff95cd827a, resultRelInfo=0x624cb2a62420,
context=0x7fff95cd8340) at nodeModifyTable.c:2819
...

Clarification.
--------------
In the query "INSERT ... ON CONFLICT ... UPDATE ..." when executing
INSERT, a conflict is triggered. But when trying to execute UPDATE, our
tuple has already been moved to another partition and Assert is
triggered. I think this is a correct situation and in this case we
should generate an error instead of Assert.

Fixing.
-------
Patch [v1-0001-Replace-invalid-Assert-with-ereport-ERROR.patch].
For testing need to apply
[v1-0001-Replace-invalid-Assert-with-ereport-ERROR.patch]:

git am v1-0001-Replace-invalid-Assert-with-ereport-ERROR.patch

rebuild postgres (2) and run test again (3),

--
With best regards,
Dmitry Koval

Postgres Professional: http://postgrespro.com

Attachment Content-Type Size
v1-0001-Triggering-Assert-on-query-with-ON-CONFLICT.no_cfbot text/plain 4.2 KB
v1-0001-Replace-invalid-Assert-with-ereport-ERROR.patch text/plain 1.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2025-12-18 23:30:05 A few patches to clarify snapshot management, part 2
Previous Message Peter Smith 2025-12-18 23:21:55 Re: DOCS - Clarify the publication 'publish_via_partition_root' default value.