Re: BUG #17811: Replacing an underlying view breaks OLD/NEW tuple when accessing it via upper-level view
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: exclusion@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Date: 2023-03-07T18:43:05Z
Lists: pgsql-bugs
Attachments
- fix-bug-17811.patch (text/x-diff) patch
PG Bug reporting form <noreply@postgresql.org> writes: > I've discovered an issue with replacing a view when there is another > updatable view defined on top of it and the new underlying view has > more columns than the previous one. I've looked into this a bit more, and both of these symptoms reduce to the same thing: after we've plugged the modified view's query into the upper query, we have an RTE_SUBQUERY RTE whose eref->colnames list is shorter than the number of columns actually available from the subquery. This breaks assorted code that is expecting that it can use list_length(eref->colnames) as a quick guide to the number of output columns. We have seen this before (bug #14876, commit d5b760ecb) and at the time our response was to patch up the code making such an assumption. But you've just demonstrated at least two other places with the same issue, so now I'm feeling that we'd be best advised to fix it centrally in the rewriter code that plugs in the view definition. The attached fix causes a change in the regression test output for bug #14876's test case, but AFAICS the change is a strict improvement: we get something sane, not a NULL, for the added column. I'm not sure whether to change the code added to expandRTE in d5b760ecb or leave it be. We could make it into elog(ERROR) now, perhaps. regards, tom lane
Commits
-
Fix more bugs caused by adding columns to the end of a view.
- 99be6feec971 16.0 landed
- 76d2177fb693 15.3 landed
- 9f1e51b59673 14.8 landed
- 721626cb57c0 11.20 landed
- 695b34ab359d 13.11 landed
- 5a19da58eed2 12.15 landed
-
Fix crash when columns have been added to the end of a view.
- d5b760ecb5e1 11.0 cited