From 5ec915941dd6c884da31532634aff74a8ebb48a9 Mon Sep 17 00:00:00 2001
From: Muhammad Taha Naveed <m.taha.naveed27@gmail.com>
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

