[Bug][patch]: After dropping the last label from a property graph element, invoking pg_get_propgraphdef() triggers an assertion failure

From: SATYANARAYANA NARLAPURAM <satyanarlapuram(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
Subject: [Bug][patch]: After dropping the last label from a property graph element, invoking pg_get_propgraphdef() triggers an assertion failure
Date: 2026-04-20 18:12:44
Message-ID: CAHg+QDeP=mTHTV48R23zKMy1SBmCKZ_L7-z5zKnYyw+K0x-gCg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

ALTER PROPERTY GRAPH ... ALTER ... DROP LABEL currently allows removing
the last label from an element, leaving it with zero labels.

On assert-enabled builds, pg_get_propgraphdef() hits
TRAP: failed Assert("count > 0"), File: "ruleutils.c", Line: 1837, PID:
1821840

Repro:

CREATE TABLE t (x int PRIMARY KEY, y int, z int);
CREATE PROPERTY GRAPH g VERTEX TABLES (t KEY (x) LABEL l1 LABEL l2);
ALTER PROPERTY GRAPH g ALTER VERTEX TABLE t DROP LABEL l2;
ALTER PROPERTY GRAPH g ALTER VERTEX TABLE t DROP LABEL l1;
SELECT pg_get_propgraphdef('g'::regclass);

We can fix it two ways, (1) Prevent dropping the last label; (2) handle
zero labels.
I feel it is easier to prevent dropping the last label than handling zero
labels. Thoughts?

The attached patch adds a check in AlterPropGraph() before
performDeletion(). It scans pg_propgraph_element_label to count labels
for the element, and raises an error if only one remains. A regression test
is included
that drops labels down to the last one, verifies the error, then re-adds
them back.

Thanks,
Satya

Attachment Content-Type Size
0001-Prevent-dropping-the-last-label-from-a-property-grap.patch application/octet-stream 4.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Korotkov 2026-04-20 18:45:51 Re: Implement waiting for wal lsn replay: reloaded
Previous Message Antonin Houska 2026-04-20 17:44:52 Re: Adding REPACK [concurrently]