[PATCH] SQL/PGQ: Fix inferred property graph keys with INCLUDE columns
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.
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:t253560psql -h localhost -U postgresBuilt 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.gitIn a checkout you already have, add the fork once:
git remote add hackorum https://github.com/hackorum-dev/postgres.gitthen, for this patchset and every later one:
git fetch hackorum t253560_1 && git checkout t253560_1Patchset v1 (message #1) is on t253560_1
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