Re: BUG #18077: PostgreSQL server subprocess crashed by a SELECT statement with WITH clause
Richard Guo <guofenglinux@gmail.com>
From: Richard Guo <guofenglinux@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: fuboat@outlook.com, pgsql-bugs@lists.postgresql.org
Date: 2023-09-05T02:37:33Z
Lists: pgsql-bugs
Attachments
- v3-0001-Fix-expanding-Var-of-type-RECORD.patch (application/octet-stream) patch v3-0001
On Tue, Sep 5, 2023 at 10:04 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Richard Guo <guofenglinux@gmail.com> writes:
> > BTW, do you think get_name_for_var_field() has similar problem for
> > RTE_SUBQUERY case? The RTE_CTE code path in that function crawls up the
> > namespace stack before recursing into the CTE while the RTE_SUBQUERY
> > code patch does not, which looks like an oversight.
>
> Hmm, seems suspicious ...
>
> > I tried to find a
> > test case to show it's indeed a problem but with no luck.
>
> Note that any test case here would be of the form "dump a view
> or rule definition", not "EXPLAIN". What did you try?
Ah, thanks. I got one of the form "dump a view" leveraging your test
case from the v2 patch (with a minor tweak).
create view composite_v as
with cte(c) as materialized (select row(1, 2)),
cte2(c) as (select * from cte)
select 1 from cte2 as t
where (select * from (select c as c1) s
where (select (c1).f1 > 0)) is not null;
select pg_get_viewdef('composite_v', true);
ERROR: bogus varno: 1
So it is indeed a problem!
Here is v3 patch which is v2 + fix for this issue.
Thanks
Richard
Commits
-
Track nesting depth correctly when drilling down into RECORD Vars.
- e0e492e5a928 17.0 landed
- d29812c0c6cd 12.17 landed
- c5b7f791dab9 13.13 landed
- ae13f8166dc3 14.10 landed
- a374f6c61681 11.22 landed
- 53630f12d39b 16.1 landed
- 2679a107a152 15.5 landed
-
Fix get_expr_result_type() to find field names for RECORD Consts.
- 8a15b4178c40 12.17 landed
- 59bc0dfe44a6 13.13 landed
- 479b99125dcc 11.22 landed
-
Allow extracting fields from a ROW() expression in more cases.
- ece1154f4c89 11.22 landed
- 2f02d4a2b9cb 12.17 landed