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

Поиск
Список
Период
Сортировка
Искать

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

От:
Taha 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
FAQ