firtst release
Revision | 2c3793d74fadd4897b94a896dd254541097c035d (tree) |
---|---|
Time | 2014-01-20 13:31:29 |
Author | Takashi Suzuki <suzuki.takashi@metr...> |
Commiter | Takashi Suzuki |
既存の流用関数の更新に伴い、流用関数を追加した。
流用関数を更新した結果、新しいstatistic関数を使用していたため。
@@ -6,6 +6,7 @@ | ||
6 | 6 | * src/backend/optimizer/path/allpaths.c |
7 | 7 | * set_append_rel_pathlist() |
8 | 8 | * generate_mergeappend_paths() |
9 | + * get_cheapest_parameterized_child_path() | |
9 | 10 | * accumulate_append_subpath() |
10 | 11 | * standard_join_search() |
11 | 12 | * |
@@ -307,6 +308,79 @@ generate_mergeappend_paths(PlannerInfo *root, RelOptInfo *rel, | ||
307 | 308 | } |
308 | 309 | |
309 | 310 | /* |
311 | + * get_cheapest_parameterized_child_path | |
312 | + * Get cheapest path for this relation that has exactly the requested | |
313 | + * parameterization. | |
314 | + * | |
315 | + * Returns NULL if unable to create such a path. | |
316 | + */ | |
317 | +static Path * | |
318 | +get_cheapest_parameterized_child_path(PlannerInfo *root, RelOptInfo *rel, | |
319 | + Relids required_outer) | |
320 | +{ | |
321 | + Path *cheapest; | |
322 | + ListCell *lc; | |
323 | + | |
324 | + /* | |
325 | + * Look up the cheapest existing path with no more than the needed | |
326 | + * parameterization. If it has exactly the needed parameterization, we're | |
327 | + * done. | |
328 | + */ | |
329 | + cheapest = get_cheapest_path_for_pathkeys(rel->pathlist, | |
330 | + NIL, | |
331 | + required_outer, | |
332 | + TOTAL_COST); | |
333 | + Assert(cheapest != NULL); | |
334 | + if (bms_equal(PATH_REQ_OUTER(cheapest), required_outer)) | |
335 | + return cheapest; | |
336 | + | |
337 | + /* | |
338 | + * Otherwise, we can "reparameterize" an existing path to match the given | |
339 | + * parameterization, which effectively means pushing down additional | |
340 | + * joinquals to be checked within the path's scan. However, some existing | |
341 | + * paths might check the available joinquals already while others don't; | |
342 | + * therefore, it's not clear which existing path will be cheapest after | |
343 | + * reparameterization. We have to go through them all and find out. | |
344 | + */ | |
345 | + cheapest = NULL; | |
346 | + foreach(lc, rel->pathlist) | |
347 | + { | |
348 | + Path *path = (Path *) lfirst(lc); | |
349 | + | |
350 | + /* Can't use it if it needs more than requested parameterization */ | |
351 | + if (!bms_is_subset(PATH_REQ_OUTER(path), required_outer)) | |
352 | + continue; | |
353 | + | |
354 | + /* | |
355 | + * Reparameterization can only increase the path's cost, so if it's | |
356 | + * already more expensive than the current cheapest, forget it. | |
357 | + */ | |
358 | + if (cheapest != NULL && | |
359 | + compare_path_costs(cheapest, path, TOTAL_COST) <= 0) | |
360 | + continue; | |
361 | + | |
362 | + /* Reparameterize if needed, then recheck cost */ | |
363 | + if (!bms_equal(PATH_REQ_OUTER(path), required_outer)) | |
364 | + { | |
365 | + path = reparameterize_path(root, path, required_outer, 1.0); | |
366 | + if (path == NULL) | |
367 | + continue; /* failed to reparameterize this one */ | |
368 | + Assert(bms_equal(PATH_REQ_OUTER(path), required_outer)); | |
369 | + | |
370 | + if (cheapest != NULL && | |
371 | + compare_path_costs(cheapest, path, TOTAL_COST) <= 0) | |
372 | + continue; | |
373 | + } | |
374 | + | |
375 | + /* We have a new best path */ | |
376 | + cheapest = path; | |
377 | + } | |
378 | + | |
379 | + /* Return the best path, or NULL if we found no suitable candidate */ | |
380 | + return cheapest; | |
381 | +} | |
382 | + | |
383 | +/* | |
310 | 384 | * accumulate_append_subpath |
311 | 385 | * Add a subpath to the list being built for an Append or MergeAppend |
312 | 386 | * |
@@ -413,6 +413,9 @@ static void set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, | ||
413 | 413 | static void generate_mergeappend_paths(PlannerInfo *root, RelOptInfo *rel, |
414 | 414 | List *live_childrels, |
415 | 415 | List *all_child_pathkeys); |
416 | +static Path *get_cheapest_parameterized_child_path(PlannerInfo *root, | |
417 | + RelOptInfo *rel, | |
418 | + Relids required_outer); | |
416 | 419 | static List *accumulate_append_subpath(List *subpaths, Path *path); |
417 | 420 | RelOptInfo *pg_hint_plan_make_join_rel(PlannerInfo *root, RelOptInfo *rel1, |
418 | 421 | RelOptInfo *rel2); |