fix subtle bug in adding to a list we are iterating over

moonshot/custom-path
Nils Dijk 2020-05-07 19:08:47 +02:00
parent 23b11b470b
commit 6b8e0a6105
No known key found for this signature in database
GPG Key ID: CA1177EF9434F241
1 changed files with 14 additions and 1 deletions

View File

@ -383,6 +383,13 @@ PathBasedPlannerJoinHook(PlannerInfo *root,
JoinType jointype, JoinType jointype,
JoinPathExtraData *extra) JoinPathExtraData *extra)
{ {
/*
* Adding a path to a list includes lappend which might be destructive. Since we are
* looping over the paths we are adding to we should keep a list of new paths to add
* and only add them after we have found all the paths we want to add.
*/
List *newPaths = NIL;
if (jointype == JOIN_INNER) if (jointype == JOIN_INNER)
{ {
ListCell *pathCell = NULL; ListCell *pathCell = NULL;
@ -392,10 +399,16 @@ PathBasedPlannerJoinHook(PlannerInfo *root,
Path *optimizedPath = OptimizeJoinPath(originalPath); Path *optimizedPath = OptimizeJoinPath(originalPath);
if (optimizedPath) if (optimizedPath)
{ {
add_path(joinrel, optimizedPath); newPaths = lappend(newPaths, optimizedPath);
} }
} }
} }
Path *path = NULL;
foreach_ptr(path, newPaths)
{
add_path(joinrel, path);
}
} }
/* /*