MCPcopy Create free account
hub / github.com/apache/cloudberry / set_cheapest

Function set_cheapest

src/backend/optimizer/util/pathnode.c:268–386  ·  view source on GitHub ↗

* set_cheapest * Find the minimum-cost paths from among a relation's paths, * and save them in the rel's cheapest-path fields. * * cheapest_total_path is normally the cheapest-total-cost unparameterized * path; but if there are no unparameterized paths, we assign it to be the * best (cheapest least-parameterized) parameterized path. However, only * unparameterized paths are considered

Source from the content-addressed store, hash-verified

266 * list for the rel node.
267 */
268void
269set_cheapest(RelOptInfo *parent_rel)
270{
271 Path *cheapest_startup_path;
272 Path *cheapest_total_path;
273 Path *best_param_path;
274 List *parameterized_paths;
275 ListCell *p;
276
277 Assert(IsA(parent_rel, RelOptInfo));
278
279 if (parent_rel->pathlist == NIL)
280 elog(ERROR, "could not devise a query plan for the given query");
281
282 cheapest_startup_path = cheapest_total_path = best_param_path = NULL;
283 parameterized_paths = NIL;
284
285 foreach(p, parent_rel->pathlist)
286 {
287 Path *path = (Path *) lfirst(p);
288 int cmp;
289
290 if (path->param_info)
291 {
292 /* Parameterized path, so add it to parameterized_paths */
293 parameterized_paths = lappend(parameterized_paths, path);
294
295 /*
296 * If we have an unparameterized cheapest-total, we no longer care
297 * about finding the best parameterized path, so move on.
298 */
299 if (cheapest_total_path)
300 continue;
301
302 /*
303 * Otherwise, track the best parameterized path, which is the one
304 * with least total cost among those of the minimum
305 * parameterization.
306 */
307 if (best_param_path == NULL)
308 best_param_path = path;
309 else
310 {
311 switch (bms_subset_compare(PATH_REQ_OUTER(path),
312 PATH_REQ_OUTER(best_param_path)))
313 {
314 case BMS_EQUAL:
315 /* keep the cheaper one */
316 if (compare_path_costs(path, best_param_path,
317 TOTAL_COST) < 0)
318 best_param_path = path;
319 break;
320 case BMS_SUBSET1:
321 /* new path is less-parameterized */
322 best_param_path = path;
323 break;
324 case BMS_SUBSET2:
325 /* old path is less-parameterized, keep it */

Callers 15

create_two_stage_pathsFunction · 0.85
make_subplanFunction · 0.85
query_plannerFunction · 0.85
standard_plannerFunction · 0.85
subquery_plannerFunction · 0.85
grouping_plannerFunction · 0.85
create_grouping_pathsFunction · 0.85
create_window_pathsFunction · 0.85
create_distinct_pathsFunction · 0.85

Calls 6

lappendFunction · 0.85
bms_subset_compareFunction · 0.85
compare_path_costsFunction · 0.85
compare_pathkeysFunction · 0.85
lconsFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected