Monthly Summary: (SQL/PGQ) cache lookup failed for label — May 2026
Overview
A dependency-tracking bug in PostgreSQL's SQL/PGQ (Property Graph Queries) implementation was reported, diagnosed, patched, reviewed through multiple iterations, and brought to "Ready for Committer" status within the month. The bug allowed ALTER PROPERTY GRAPH ... DROP LABEL to succeed even when views referenced the label, causing subsequent cache lookup failed for label <OID> errors. The root cause was that find_expr_references_walker in dependency.c never descended into graph-specific node types (GraphLabelRef, GraphPropertyRef), so no pg_depend rows were ever recorded connecting views to label/property objects.
Key Developments
Bug Diagnosis and Initial Patch (Zeng Man)
The original reporter demonstrated the issue: creating a view over GRAPH_TABLE(... MATCH (a IS l2) ...), then dropping label l2 via ALTER PROPERTY GRAPH, then getting cache lookup failed on view access. The initial patch added handlers for GraphLabelRef and GraphPropertyRef in find_expr_references_walker and manually iterated through RTE_GRAPH_TABLE's graph_pattern substructure.
Reviewer Feedback (Ashutosh Bapat)
Bapat identified several issues with the original approach:
- Should use
foreach_node()macro instead of genericforeach() - Must also walk
rte->graph_table_columns(not just the MATCH pattern) - Tests should go in
graph_table.sqland include DROP PROPERTY coverage - Patch depends on a related thread's error message changes
Handoff and Architectural Simplification (Ayush Tiwari)
Zeng Man stepped back due to time constraints. Ayush Tiwari took over with a cleaner approach: since query_tree_walker() already descends into rte->graph_pattern and rte->graph_table_columns, only leaf-node handlers for GraphLabelRef and GraphPropertyRef are needed — no manual iteration required. This went through v1→v3 with incremental test improvements.
Committer-Level Revision (Ashutosh Bapat)
Bapat posted a near-final revision with:
- Removed misleading comment about expression substructure
- Restructured tests to place DDL before
pg_get_viewdef()(ensuring the bug would actually manifest without the fix) - Simplified test strategy to avoid drop-and-re-add complexity
Approval and Status
Both Junwang Zhao and Ayush Tiwari gave LGTM on Bapat's revision. The Commitfest entry was marked "Ready for Committer."
Deeper Issues Identified (Not Blocking)
Bapat identified two additional architectural problems to address separately:
- Empty label expansion timing: Currently happens at rewrite phase but should move to transform (parse analysis) so that resolved labels get
pg_dependrows and are captured in catalog/dump representations - Label removal edge cases: Dropping a label from vertex tables (but not edge tables) produces obscure errors rather than clear dependency violations; may require making vertex/edge labels separate catalog objects
Current Status
The dependency-tracking fix is ready to commit. The deeper architectural issues (empty label expansion timing, vertex/edge label distinction) will be addressed in follow-up patches once the approach is decided.