[PATCH] SQL/PGQ: Fix inferred property graph keys with INCLUDE columns

From: Taha Naveed <m(dot)taha(dot)naveed27(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: [PATCH] SQL/PGQ: Fix inferred property graph keys with INCLUDE columns
Date: 2026-08-26 21:12:51
Message-ID: CAPTqav+VUjYgm1jZy0Scy=1-PfdgznVj2=PwH8disiXF76HEow@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I found an issue with inferred property graph keys when a primary key has
INCLUDE columns. I reproduced it on PG 19beta3 and current master
(b941cace8b2).

CREATE TABLE vertex (
id integer,
payload text,
PRIMARY KEY (id) INCLUDE (payload)
);

CREATE PROPERTY GRAPH g
VERTEX TABLES (vertex);

SELECT indnatts, indnkeyatts, indkey
FROM pg_index
WHERE indexrelid = 'vertex_pkey'::regclass;

indnatts | indnkeyatts | indkey
----------+-------------+--------
2 | 1 | 1 2
(1 row)

SELECT pgekey
FROM pg_propgraph_element
WHERE pgepgid = 'g'::regclass;

pgekey
--------
{1,2}
(1 row)

SELECT pg_get_propgraphdef('g'::regclass);

pg_get_propgraphdef
-----------------------------------------------------------
CREATE PROPERTY GRAPH public.g +
VERTEX TABLES ( +
vertex KEY (id, payload) PROPERTIES (id, payload)+
)
(1 row)

The primary key index has one key attribute, but pgekey contains both
attributes. Consequently, pg_get_propgraphdef() emits KEY (id, payload).
Only id should be part of the inferred graph key.

The problem is that propgraph_element_get_key() uses indkey.dim1, which
includes non key INCLUDE attributes. The attached patch uses
IndexRelationGetNumberOfKeyAttributes() instead.

Regards,
Taha

Attachment Content-Type Size
v1-0001-Fix-inferred-property-graph-keys-with-INCLUDE-col.patch application/x-patch 2.6 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Sami Imseih 2026-08-26 21:17:13 Re: tablecmds: fix bug where index rebuild loses replica identity on partitions
Previous Message Mihail Nikalayeu 2026-08-26 21:06:00 Re: Apply worker can pick an invalid index for REPLICA IDENTITY FULL lookups