Re: BUG #17646: create rule named "_RETURN" will cause pg core
Ilya Anfimov <ilan@tzirechnoy.com>
From: Ilya Anfimov <ilan@tzirechnoy.com>
To: pgsql-bugs@lists.postgresql.org
Date: 2022-10-17T15:15:57Z
Lists: pgsql-bugs
On Mon, Oct 17, 2022 at 10:41:35AM -0400, Tom Lane wrote:
> Ilya Anfimov <ilan@tzirechnoy.com> writes:
> > On Mon, Oct 17, 2022 at 10:17:55AM -0400, Tom Lane wrote:
> >> (Although the core dump is also not great --- something should've noticed
> >> the bogosity of the plan earlier than this.)
>
> > Id doesn't look much of a plan bogosity,
> > but rather implicit deletion of the "_RETURN" on select rule.
>
> Right, but then since there's no applicable rule, we end up generating
> a plan that tries to do a seqscan directly on the view relation,
> which of course lacks storage. Something should notice that a little
> sooner than segfaulting because of rel->rd_tableam being NULL --- it's
> not like we don't have hundreds of other sanity checks for not-really-
> supposed-to-happen catalog corruption.
>
> In versions before v12, I get something like
>
> regression=# select * from v1;
> ERROR: could not open file "base/16384/49209": No such file or directory
>
> which is a shade less bad, but still not great.
Another solution would be to always create a real heap file and let
anyone dropped to that state select it, if he wishes.
btw, the documentation clearly says that it does so:
https://www.postgresql.org/docs/14/rules-views.html
<<In fact, there is essentially no difference between:
CREATE VIEW myview AS SELECT * FROM mytab;
compared against the two commands:
CREATE TABLE myview (same column list as mytab);
CREATE RULE "_RETURN" AS ON SELECT TO myview DO INSTEAD
SELECT * FROM mytab;
because this is exactly what the CREATE VIEW command does internally. >>
Commits
-
Reject non-ON-SELECT rules that are named "_RETURN".
- ecf4ce689a7c 10.23 landed
- e9377e3e53e6 11.18 landed
- b21615d1e9b0 13.9 landed
- 797e313dc9ae 16.0 landed
- 65c1106d8c5b 12.13 landed
- 4a41a069e7ac 15.1 landed
- 2f26cec48843 14.6 landed
-
Guard against table-AM-less relations in planner.
- eec34661182d 16.0 landed
- 99b6b705d439 12.13 landed
- 8c611602bd35 14.6 landed
- 62b263bf779e 13.9 landed
- 2e3326929b0b 15.1 landed