diff options
Diffstat (limited to 'src/backend/optimizer/util/pathnode.c')
-rw-r--r-- | src/backend/optimizer/util/pathnode.c | 51 |
1 files changed, 13 insertions, 38 deletions
diff --git a/src/backend/optimizer/util/pathnode.c b/src/backend/optimizer/util/pathnode.c index d884d2bb000..67254c2fd91 100644 --- a/src/backend/optimizer/util/pathnode.c +++ b/src/backend/optimizer/util/pathnode.c @@ -423,11 +423,9 @@ void add_path(RelOptInfo *parent_rel, Path *new_path) { bool accept_new = true; /* unless we find a superior old path */ - ListCell *insert_after = NULL; /* where to insert new item */ + int insert_at = 0; /* where to insert new item */ List *new_path_pathkeys; ListCell *p1; - ListCell *p1_prev; - ListCell *p1_next; /* * This is a convenient place to check for query cancel --- no part of the @@ -442,12 +440,8 @@ add_path(RelOptInfo *parent_rel, Path *new_path) * Loop to check proposed new path against old paths. Note it is possible * for more than one old path to be tossed out because new_path dominates * it. - * - * We can't use foreach here because the loop body may delete the current - * list cell. */ - p1_prev = NULL; - for (p1 = list_head(parent_rel->pathlist); p1 != NULL; p1 = p1_next) + foreach(p1, parent_rel->pathlist) { Path *old_path = (Path *) lfirst(p1); bool remove_old = false; /* unless new proves superior */ @@ -455,8 +449,6 @@ add_path(RelOptInfo *parent_rel, Path *new_path) PathKeysComparison keyscmp; BMS_Comparison outercmp; - p1_next = lnext(p1); - /* * Do a fuzzy cost comparison with standard fuzziness limit. */ @@ -593,23 +585,20 @@ add_path(RelOptInfo *parent_rel, Path *new_path) */ if (remove_old) { - parent_rel->pathlist = list_delete_cell(parent_rel->pathlist, - p1, p1_prev); + parent_rel->pathlist = foreach_delete_current(parent_rel->pathlist, + p1); /* * Delete the data pointed-to by the deleted cell, if possible */ if (!IsA(old_path, IndexPath)) pfree(old_path); - /* p1_prev does not advance */ } else { /* new belongs after this old path if it has cost >= old's */ if (new_path->total_cost >= old_path->total_cost) - insert_after = p1; - /* p1_prev advances */ - p1_prev = p1; + insert_at = foreach_current_index(p1) + 1; } /* @@ -624,10 +613,8 @@ add_path(RelOptInfo *parent_rel, Path *new_path) if (accept_new) { /* Accept the new path: insert it at proper place in pathlist */ - if (insert_after) - lappend_cell(parent_rel->pathlist, insert_after, new_path); - else - parent_rel->pathlist = lcons(new_path, parent_rel->pathlist); + parent_rel->pathlist = + list_insert_nth(parent_rel->pathlist, insert_at, new_path); } else { @@ -763,10 +750,8 @@ void add_partial_path(RelOptInfo *parent_rel, Path *new_path) { bool accept_new = true; /* unless we find a superior old path */ - ListCell *insert_after = NULL; /* where to insert new item */ + int insert_at = 0; /* where to insert new item */ ListCell *p1; - ListCell *p1_prev; - ListCell *p1_next; /* Check for query cancel. */ CHECK_FOR_INTERRUPTS(); @@ -781,16 +766,12 @@ add_partial_path(RelOptInfo *parent_rel, Path *new_path) * As in add_path, throw out any paths which are dominated by the new * path, but throw out the new path if some existing path dominates it. */ - p1_prev = NULL; - for (p1 = list_head(parent_rel->partial_pathlist); p1 != NULL; - p1 = p1_next) + foreach(p1, parent_rel->partial_pathlist) { Path *old_path = (Path *) lfirst(p1); bool remove_old = false; /* unless new proves superior */ PathKeysComparison keyscmp; - p1_next = lnext(p1); - /* Compare pathkeys. */ keyscmp = compare_pathkeys(new_path->pathkeys, old_path->pathkeys); @@ -841,17 +822,14 @@ add_partial_path(RelOptInfo *parent_rel, Path *new_path) if (remove_old) { parent_rel->partial_pathlist = - list_delete_cell(parent_rel->partial_pathlist, p1, p1_prev); + foreach_delete_current(parent_rel->partial_pathlist, p1); pfree(old_path); - /* p1_prev does not advance */ } else { /* new belongs after this old path if it has cost >= old's */ if (new_path->total_cost >= old_path->total_cost) - insert_after = p1; - /* p1_prev advances */ - p1_prev = p1; + insert_at = foreach_current_index(p1) + 1; } /* @@ -866,11 +844,8 @@ add_partial_path(RelOptInfo *parent_rel, Path *new_path) if (accept_new) { /* Accept the new path: insert it at proper place */ - if (insert_after) - lappend_cell(parent_rel->partial_pathlist, insert_after, new_path); - else - parent_rel->partial_pathlist = - lcons(new_path, parent_rel->partial_pathlist); + parent_rel->partial_pathlist = + list_insert_nth(parent_rel->partial_pathlist, insert_at, new_path); } else { |