From: zengman <zengman@halodbtech.com>
To: pgsql-hackers <pgsql-hackers@lists.postgresql.org>
Cc: Peter Eisentraut <peter@eisentraut.org>
Cc: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Subject: (SQL/PGQ) cache lookup failed for label
Date: Fri, 8 May 2026 16:39:46 +0800
Message-ID: <tencent_43D9888041FA4FDE498C7BF1@qq.com> (raw)
Hi all,
I noticed that the following SQL statement triggers the error message `cache lookup failed for label`.
```sql
CREATE TABLE vt (id text PRIMARY KEY, name text, age int);
CREATE TABLE et (id text PRIMARY KEY, src text REFERENCES vt(id), dst text REFERENCES vt(id));
INSERT INTO vt VALUES ('a', 'Alice', 30), ('b', 'Bob', 25);
INSERT INTO et VALUES ('e1', 'a', 'b');
CREATE PROPERTY GRAPH g
VERTEX TABLES (vt LABEL l1 PROPERTIES (name) LABEL l2 PROPERTIES (name, age))
EDGE TABLES (et SOURCE KEY (src) REFERENCES vt(id) DESTINATION KEY (dst) REFERENCES vt(id));
CREATE VIEW v1 AS SELECT * FROM GRAPH_TABLE(g MATCH (a IS l2)-[e IS et]->(b IS l2) COLUMNS (a.name, a.age, b.name AS bname));
ALTER PROPERTY GRAPH g ALTER VERTEX TABLE vt DROP LABEL l2;
SELECT * FROM v1;
```
Here are the actual test results; it appears to be caused by missing dependency information.
```sql
test=# CREATE TABLE vt (id text PRIMARY KEY, name text, age int);
CREATE TABLE
test=# CREATE TABLE et (id text PRIMARY KEY, src text REFERENCES vt(id), dst text REFERENCES vt(id));
CREATE TABLE
test=# INSERT INTO vt VALUES ('a', 'Alice', 30), ('b', 'Bob', 25);
INSERT 0 2
test=# INSERT INTO et VALUES ('e1', 'a', 'b');
INSERT 0 1
test=# CREATE PROPERTY GRAPH g
VERTEX TABLES (vt LABEL l1 PROPERTIES (name) LABEL l2 PROPERTIES (name, age))
EDGE TABLES (et SOURCE KEY (src) REFERENCES vt(id) DESTINATION KEY (dst) REFERENCES vt(id));
CREATE PROPERTY GRAPH
test=# CREATE VIEW v1 AS SELECT * FROM GRAPH_TABLE(g MATCH (a IS l2)-[e IS et]->(b IS l2) COLUMNS (a.name, a.age, b.name AS bname));
CREATE VIEW
test=# ALTER PROPERTY GRAPH g ALTER VERTEX TABLE vt DROP LABEL l2;
ALTER PROPERTY GRAPH
test=# SELECT * FROM v1;
2026-05-08 15:38:37.121 CST [175953] ERROR: cache lookup failed for label 16472
2026-05-08 15:38:37.121 CST [175953] STATEMENT: SELECT * FROM v1;
ERROR: cache lookup failed for label 16472
test=#
```
I've made some minor modifications; this is my diffs file. I'm not sure if anything is missing, so feel free to add to or supplement it.
```c
inline patch 1: src/backend/catalog/dependency.c (+38/-0 lines) download inline-1.patchdiff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.cindex fdb8e67e1f5..6a73b74fc9b 100644--- a/src/backend/catalog/dependency.c+++ b/src/backend/catalog/dependency.c@@ -2247,6 +2247,22 @@ find_expr_references_walker(Node *node,
context->addrs);
/* fall through to examine substructure */
}
+ if (IsA(node, GraphLabelRef))+ {+ GraphLabelRef *lref = (GraphLabelRef *) node;++ add_object_address(PropgraphLabelRelationId, lref->labelid, 0,+ context->addrs);+ return false;+ }+ if (IsA(node, GraphPropertyRef))+ {+ GraphPropertyRef *gpr = (GraphPropertyRef *) node;++ add_object_address(PropgraphPropertyRelationId, gpr->propid, 0,+ context->addrs);+ return false;+ }
else if (IsA(node, Query))
{
/* Recurse into RTE subquery or not-yet-planned sublink subquery */
@@ -2277,9 +2293,31 @@ find_expr_references_walker(Node *node,
switch (rte->rtekind)
{
case RTE_RELATION:
+ add_object_address(RelationRelationId, rte->relid, 0,+ context->addrs);+ break;
case RTE_GRAPH_TABLE:
add_object_address(RelationRelationId, rte->relid, 0,
context->addrs);
++ if (rte->graph_pattern)+ {+ GraphPattern *gp = rte->graph_pattern;+ ListCell *lc1;++ foreach(lc1, gp->path_pattern_list)+ {+ List *path_term = lfirst_node(List, lc1);+ ListCell *lc2;++ foreach(lc2, path_term)+ {+ GraphElementPattern *gep = lfirst_node(GraphElementPattern, lc2);++ find_expr_references_walker(gep->labelexpr, context);+ }+ }+ }
break;
case RTE_JOIN:
```
Final running results
```sql
test=# CREATE TABLE vt (id text PRIMARY KEY, name text, age int);
CREATE TABLE et (id text PRIMARY KEY, src text REFERENCES vt(id), dst text REFERENCES vt(id));
INSERT INTO vt VALUES ('a', 'Alice', 30), ('b', 'Bob', 25);
INSERT INTO et VALUES ('e1', 'a', 'b');
CREATE PROPERTY GRAPH g
VERTEX TABLES (vt LABEL l1 PROPERTIES (name) LABEL l2 PROPERTIES (name, age))
EDGE TABLES (et SOURCE KEY (src) REFERENCES vt(id) DESTINATION KEY (dst) REFERENCES vt(id));
CREATE VIEW v1 AS SELECT * FROM GRAPH_TABLE(g MATCH (a IS l2)-[e IS et]->(b IS l2) COLUMNS (a.name, a.age, b.name AS bname));
ALTER PROPERTY GRAPH g ALTER VERTEX TABLE vt DROP LABEL l2;
SELECT * FROM v1;
CREATE TABLE
CREATE TABLE
INSERT 0 2
INSERT 0 1
CREATE PROPERTY GRAPH
CREATE VIEW
2026-05-08 16:24:59.938 CST [182833] ERROR: cannot drop label l2 of property graph g because other objects depend on it
2026-05-08 16:24:59.938 CST [182833] DETAIL: view v1 depends on label l2 of property graph g
2026-05-08 16:24:59.938 CST [182833] HINT: Use DROP ... CASCADE to drop the dependent objects too.
2026-05-08 16:24:59.938 CST [182833] STATEMENT: ALTER PROPERTY GRAPH g ALTER VERTEX TABLE vt DROP LABEL l2;
ERROR: cannot drop label l2 of property graph g because other objects depend on it
DETAIL: view v1 depends on label l2 of property graph g
HINT: Use DROP ... CASCADE to drop the dependent objects too.
name | age | bname
-------+-----+-------
Alice | 30 | Bob
(1 row)
```
--
regards,
Man Zeng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: zengman@halodbtech.com, pgsql-hackers@lists.postgresql.org, peter@eisentraut.org, ashutosh.bapat.oss@gmail.com
Subject: Re: (SQL/PGQ) cache lookup failed for label
In-Reply-To: <tencent_43D9888041FA4FDE498C7BF1@qq.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox