MCPcopy Create free account
hub / github.com/MariaDB/server / join_limit_shortcut_finalize_plan

Function join_limit_shortcut_finalize_plan

sql/sql_select.cc:11915–11973  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11913*/
11914
11915POSITION *join_limit_shortcut_finalize_plan(JOIN *join, double *cost)
11916{
11917 Json_writer_object wrapper(join->thd);
11918 Json_writer_object trace(join->thd, "join_limit_shortcut_choice");
11919
11920 double fraction= join->select_limit / join->join_record_count;
11921 trace.add("limit_fraction", fraction);
11922
11923 /* Check which fraction of join output we need */
11924 if (fraction >= 1.0)
11925 {
11926 trace.add("skip_adjustment", "no short-cutting");
11927 return NULL;
11928 }
11929
11930 /*
11931 Check if the first table's access method produces the required ordering.
11932 Possible options:
11933 1. Yes: we can just take a fraction of the execution cost.
11934 2A No: change the access method to one that does produce the required
11935 ordering, update the costs.
11936 2B No: Need to pass the first table to filesort().
11937 */
11938 bool skip_sorting;
11939 bool access_method_changed;
11940 double new_access_cost;
11941 {
11942 Json_writer_array tmp(join->thd, "test_if_skip_sort_order_early");
11943 skip_sorting= test_if_skip_sort_order_early(join,
11944 &access_method_changed,
11945 &new_access_cost);
11946 }
11947 trace.add("can_skip_filesort", skip_sorting);
11948
11949 double cost_with_shortcut=
11950 recompute_join_cost_with_limit(join, skip_sorting,
11951 access_method_changed ?
11952 &new_access_cost : (double*)0,
11953 fraction);
11954 double risk_ratio=
11955 (double)join->thd->variables.optimizer_join_limit_pref_ratio;
11956 trace.add("full_join_cost", join->best_read);
11957 trace.add("risk_ratio", risk_ratio);
11958 trace.add("shortcut_join_cost", cost_with_shortcut);
11959 cost_with_shortcut *= risk_ratio;
11960 trace.add("shortcut_cost_with_risk", cost_with_shortcut);
11961 if (cost_with_shortcut < join->best_read)
11962 {
11963 trace.add("use_shortcut_cost", true);
11964 POSITION *pos= (POSITION*)memdup_root(join->thd->mem_root,
11965 join->best_positions,
11966 sizeof(POSITION)*
11967 (join->table_count + 1));
11968 *cost= cost_with_shortcut;
11969 return pos;
11970 }
11971 trace.add("use_shortcut_cost", false);
11972 return NULL;

Callers 1

choose_planFunction · 0.85

Calls 4

memdup_rootFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected