]> granicus.if.org Git - postgresql/commit
Fix crash when columns have been added to the end of a view.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 27 Oct 2017 21:10:21 +0000 (17:10 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 27 Oct 2017 21:10:21 +0000 (17:10 -0400)
commitddde3b4f3e888c06f7b866575be242357d9d72be
tree831346bac0de8bb4b6ec9df560f7de2ffbbde17b
parent8be1022425a395aa4d05b8032aeb9f6b128ea902
Fix crash when columns have been added to the end of a view.

expandRTE() supposed that an RTE_SUBQUERY subquery must have exactly
as many non-junk tlist items as the RTE has column aliases for it.
This was true at the time the code was written, and is still true so
far as parse analysis is concerned --- but when the function is used
during planning, the subquery might have appeared through insertion
of a view that now has more columns than it did when the outer query
was parsed.  This results in a core dump if, for instance, we have
to expand a whole-row Var that references the subquery.

To avoid crashing, we can either stop expanding the RTE when we run
out of aliases, or invent new aliases for the added columns.  While
the latter might be more useful, the former is consistent with what
expandRTE() does for composite-returning functions in the RTE_FUNCTION
case, so it seems like we'd better do it that way.

Per bug #14876 from Samuel Horwitz.  This has been busted since commit
ff1ea2173 allowed views to acquire more columns, so back-patch to all
supported branches.

Discussion: https://postgr.es/m/20171026184035.1471.82810@wrigleys.postgresql.org
src/backend/parser/parse_relation.c
src/test/regress/expected/alter_table.out
src/test/regress/sql/alter_table.sql