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

Started by Taha Naveed25 days ago2 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

This thread has been committed, so CI has stopped here. Anything below is the last result it produced.

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t253560
psql -h localhost -U postgres

Built from patchset v1 (message #1), August 26, 2026 at 09:25 PM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t253560_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t253560_1 && git checkout t253560_1

Patchset v1 (message #1) is on t253560_1

Jump to latest
#1Taha Naveed
m.taha.naveed27@gmail.com

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

Attachments:

t253560_1
v1-0001-Fix-inferred-property-graph-keys-with-INCLUDE-col.patchapplication/x-patch; name=v1-0001-Fix-inferred-property-graph-keys-with-INCLUDE-col.patchDownload+4-4
#2Peter Eisentraut
peter_e@gmx.net
In reply to: Taha Naveed (#1)
Re: [PATCH] SQL/PGQ: Fix inferred property graph keys with INCLUDE columns

On 26.08.26 23:12, Taha Naveed wrote:

I found an issue with inferred property graph keys when a primary key
has INCLUDE columns.

Fix committed, thanks.