| From: | SATYANARAYANA NARLAPURAM <satyanarlapuram(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com> |
| Subject: | Bug: pg_get_viewdef() fails on GRAPH_TABLE views with lateral column references |
| Date: | 2026-04-18 07:56:19 |
| Message-ID: | CAHg+QDcLVa2iBnggkHxY4itZbXtDMfsYHEjnCUYe9hNbnxDi-w@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi hackers,
pg_get_viewdef() fails with ERROR: bogus varlevelsup: 0 offset 0 for any
view containing a GRAPH_TABLE whose COLUMNS clause references an outer
(lateral)
table. This also breaks pg_dump and \d+ for any database containing such a
view.
Repro:
CREATE TABLE vtab (id int PRIMARY KEY, name text);
CREATE TABLE etab (eid int PRIMARY KEY,
src int REFERENCES vtab(id), dst int REFERENCES vtab(id));
CREATE PROPERTY GRAPH g1
VERTEX TABLES (vtab)
EDGE TABLES (etab KEY (eid)
SOURCE KEY (src) REFERENCES vtab(id)
DESTINATION KEY (dst) REFERENCES vtab(id));
CREATE TABLE outer_t (val int);
CREATE VIEW v AS
SELECT * FROM outer_t,
GRAPH_TABLE (g1 MATCH (a IS vtab)
COLUMNS (a.name AS src_name, outer_t.val AS oval));
pg_dump -d foo -p 5433
pg_dump: error: query failed: ERROR: bogus varlevelsup: 0 offset 0
pg_dump: detail: Query was: SELECT
pg_catalog.pg_get_viewdef('173849'::pg_catalog.oid) AS viewdef
Problem:
deparse_context context variable declared in the case RTE_GRAPH_TABLE
shadows the function's
deparse_context *context parameter. The zeroed struct has namespaces = NIL,
so when get_rule_expr()
reaches a Var node, get_variable() sees list_length(context->namespaces) ==
0 and raises the error. Property
references are fine because GraphPropertyRef deparsing never touches
namespaces.
Fix:
Remove the shadowing local variable and pass the outer context pointer to
get_rule_expr(). Attached a patch
with a fix, additionally added a test.
Thanks,
Satya
| Attachment | Content-Type | Size |
|---|---|---|
| 0001-Fix-pg_get_viewdef-crash-for-GRAPH_TABLE-views-with-.patch | application/octet-stream | 4.9 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Alexander Korotkov | 2026-04-18 07:58:42 | Re: test: avoid redundant standby catchup in 049_wait_for_lsn |
| Previous Message | David Rowley | 2026-04-18 07:53:40 | Re: Add bms_offset_members() function for bitshifting Bitmapsets |