Skip to content

Commit fc4089f

Browse files
committed
Fix possible crash in add_paths_to_append_rel()
While working on a8a968a, I failed to consider that cheapest_startup_path can be NULL when there is no non-parameterized path in the pathlist. This is well documented in set_cheapest(), I just failed to notice. Here we adjust the code to just check if the RelOptInfo has a cheapest_startup_path set before adding it to the startup_subpaths list. Reported-by: Richard Guo Author: Richard Guo Discussion: https://postgr.es/m/CAMbWs49w3t03V69XhdCuw+GDwivny4uQUxrkVp6Gejaspt0wMQ@mail.gmail.com
1 parent 4f3b56e commit fc4089f

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

src/backend/optimizer/path/allpaths.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,14 +1350,17 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
13501350

13511351
/*
13521352
* When the planner is considering cheap startup plans, we'll also
1353-
* collect all the cheapest_startup_paths and build an AppendPath
1354-
* containing those as subpaths.
1353+
* collect all the cheapest_startup_paths (if set) and build an
1354+
* AppendPath containing those as subpaths.
13551355
*/
1356-
if (rel->consider_startup && childrel->pathlist != NIL &&
1357-
childrel->cheapest_startup_path->param_info == NULL)
1356+
if (rel->consider_startup && childrel->cheapest_startup_path != NULL)
1357+
{
1358+
/* cheapest_startup_path must not be a parameterized path. */
1359+
Assert(childrel->cheapest_startup_path->param_info == NULL);
13581360
accumulate_append_subpath(childrel->cheapest_startup_path,
13591361
&startup_subpaths,
13601362
NULL);
1363+
}
13611364
else
13621365
startup_subpaths_valid = false;
13631366

src/test/regress/expected/union.out

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,3 +1453,19 @@ inner join tenk2 t2 on t1.tenthous = t2.tenthous
14531453
-> Result
14541454
(8 rows)
14551455

1456+
-- Ensure there is no problem if cheapest_startup_path is NULL
1457+
explain (costs off)
1458+
select * from tenk1 t1
1459+
left join lateral
1460+
(select t1.tenthous from tenk2 t2 union all (values(1)))
1461+
on true limit 1;
1462+
QUERY PLAN
1463+
-------------------------------------------------------------------
1464+
Limit
1465+
-> Nested Loop Left Join
1466+
-> Seq Scan on tenk1 t1
1467+
-> Append
1468+
-> Index Only Scan using tenk2_hundred on tenk2 t2
1469+
-> Result
1470+
(6 rows)
1471+

src/test/regress/sql/union.sql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,4 +550,11 @@ explain (costs off)
550550
select t1.unique1 from tenk1 t1
551551
inner join tenk2 t2 on t1.tenthous = t2.tenthous
552552
union all
553-
(values(1)) limit 1;
553+
(values(1)) limit 1;
554+
555+
-- Ensure there is no problem if cheapest_startup_path is NULL
556+
explain (costs off)
557+
select * from tenk1 t1
558+
left join lateral
559+
(select t1.tenthous from tenk2 t2 union all (values(1)))
560+
on true limit 1;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy