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
From 5ec915941dd6c884da31532634aff74a8ebb48a9 Mon Sep 17 00:00:00 2001
From: Muhammad Taha Naveed <[email protected]>
Date: Thu, 27 Aug 2026 01:17:27 +0500
Subject: [PATCH v1] Fix inferred property graph keys with INCLUDE columns
Inferred property graph keys used all attributes stored in the primary
key index, causing non-key INCLUDE columns to become part of the graph
key. Use only the index's key attributes.
---
src/backend/commands/propgraphcmds.c | 3 ++-
src/test/regress/expected/create_property_graph.out | 2 +-
src/test/regress/sql/create_property_graph.sql | 2 +-
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/backend/commands/propgraphcmds.c b/src/backend/commands/propgraphcmds.c
index 076005226f2..2bdce331c49 100644
--- a/src/backend/commands/propgraphcmds.c
+++ b/src/backend/commands/propgraphcmds.c
@@ -342,7 +342,8 @@ propgraph_element_get_key(ParseState *pstate, const List *key_clause, Relation e
Relation indexDesc;
indexDesc = index_open(pkidx, AccessShareLock);
- a = array_from_attnums(indexDesc->rd_index->indkey.dim1, indexDesc->rd_index->indkey.values);
+ a = array_from_attnums(IndexRelationGetNumberOfKeyAttributes(indexDesc),
+ indexDesc->rd_index->indkey.values);
index_close(indexDesc, NoLock);
}
}
diff --git a/src/test/regress/expected/create_property_graph.out b/src/test/regress/expected/create_property_graph.out
index 646e5fed5e2..759a5b7222c 100644
--- a/src/test/regress/expected/create_property_graph.out
+++ b/src/test/regress/expected/create_property_graph.out
@@ -12,7 +12,7 @@ ERROR: relation "g1" already exists
CREATE TABLE t1 (a int, b text);
CREATE TABLE t2 (i int PRIMARY KEY, j int, k int);
CREATE TABLE t3 (x int, y text, z text);
-CREATE TABLE e1 (a int, i int, t text, PRIMARY KEY (a, i));
+CREATE TABLE e1 (a int, i int, t text, PRIMARY KEY (a, i) INCLUDE (t));
CREATE TABLE e2 (a int, x int, t text);
CREATE PROPERTY GRAPH g2
VERTEX TABLES (t1 KEY (a), t2 DEFAULT LABEL, t3 KEY (x) LABEL t3l1 LABEL t3l2)
diff --git a/src/test/regress/sql/create_property_graph.sql b/src/test/regress/sql/create_property_graph.sql
index b1a8d12a040..c0b3d80887a 100644
--- a/src/test/regress/sql/create_property_graph.sql
+++ b/src/test/regress/sql/create_property_graph.sql
@@ -17,7 +17,7 @@ CREATE TABLE t1 (a int, b text);
CREATE TABLE t2 (i int PRIMARY KEY, j int, k int);
CREATE TABLE t3 (x int, y text, z text);
-CREATE TABLE e1 (a int, i int, t text, PRIMARY KEY (a, i));
+CREATE TABLE e1 (a int, i int, t text, PRIMARY KEY (a, i) INCLUDE (t));
CREATE TABLE e2 (a int, x int, t text);
CREATE PROPERTY GRAPH g2
--
2.25.1