mirror of
https://github.com/postgres/postgres.git
synced 2025-10-25 13:17:41 +03:00
Fix handling of changed-Param signaling for CteScan plan nodes. We were using
the "cteParam" as a proxy for the possibility that the underlying CTE plan depends on outer-level variables or Params, but that doesn't work very well because it sometimes causes calling subqueries to be treated as SubPlans when they could be InitPlans. This is inefficient and also causes the outright failure exhibited in bug #4902. Instead, leave the cteParam out of it and copy the underlying CTE plan's extParams directly. Per bug #4902 from Marko Tiikkaja.
This commit is contained in:
@@ -469,3 +469,19 @@ WITH RECURSIVE foo(i) AS
|
||||
UNION ALL
|
||||
SELECT (i+1)::numeric(10,0) FROM foo WHERE i < 10)
|
||||
SELECT * FROM foo;
|
||||
|
||||
--
|
||||
-- test for bug #4902
|
||||
--
|
||||
with cte(foo) as ( values(42) ) values((select foo from cte));
|
||||
with cte(foo) as ( select 42 ) select * from ((select foo from cte)) q;
|
||||
|
||||
-- test CTE referencing an outer-level variable (to see that changed-parameter
|
||||
-- signaling still works properly after fixing this bug)
|
||||
select ( with cte(foo) as ( values(f1) )
|
||||
select (select foo from cte) )
|
||||
from int4_tbl;
|
||||
|
||||
select ( with cte(foo) as ( values(f1) )
|
||||
values((select foo from cte)) )
|
||||
from int4_tbl;
|
||||
|
||||
Reference in New Issue
Block a user