• R/O
  • HTTP
  • SSH
  • HTTPS

pg_hint_plan: Commit

firtst release


Commit MetaInfo

Revision2c3793d74fadd4897b94a896dd254541097c035d (tree)
Time2014-01-20 13:31:29
AuthorTakashi Suzuki <suzuki.takashi@metr...>
CommiterTakashi Suzuki

Log Message

既存の流用関数の更新に伴い、流用関数を追加した。

流用関数を更新した結果、新しいstatistic関数を使用していたため。

Change Summary

Incremental Difference

--- a/core.c
+++ b/core.c
@@ -6,6 +6,7 @@
66 * src/backend/optimizer/path/allpaths.c
77 * set_append_rel_pathlist()
88 * generate_mergeappend_paths()
9+ * get_cheapest_parameterized_child_path()
910 * accumulate_append_subpath()
1011 * standard_join_search()
1112 *
@@ -307,6 +308,79 @@ generate_mergeappend_paths(PlannerInfo *root, RelOptInfo *rel,
307308 }
308309
309310 /*
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+/*
310384 * accumulate_append_subpath
311385 * Add a subpath to the list being built for an Append or MergeAppend
312386 *
--- a/pg_hint_plan.c
+++ b/pg_hint_plan.c
@@ -413,6 +413,9 @@ static void set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
413413 static void generate_mergeappend_paths(PlannerInfo *root, RelOptInfo *rel,
414414 List *live_childrels,
415415 List *all_child_pathkeys);
416+static Path *get_cheapest_parameterized_child_path(PlannerInfo *root,
417+ RelOptInfo *rel,
418+ Relids required_outer);
416419 static List *accumulate_append_subpath(List *subpaths, Path *path);
417420 RelOptInfo *pg_hint_plan_make_join_rel(PlannerInfo *root, RelOptInfo *rel1,
418421 RelOptInfo *rel2);
Show on old repository browser