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

Function choose_plan

sql/sql_select.cc:10251–10381  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10249*/
10250
10251bool
10252choose_plan(JOIN *join, table_map join_tables, TABLE_LIST *emb_sjm_nest)
10253{
10254 uint search_depth= join->thd->variables.optimizer_search_depth;
10255 uint use_cond_selectivity=
10256 join->thd->variables.optimizer_use_condition_selectivity;
10257 bool straight_join= MY_TEST(join->select_options & SELECT_STRAIGHT_JOIN);
10258 THD *thd= join->thd;
10259 qsort_cmp2 jtab_sort_func;
10260 DBUG_ENTER("choose_plan");
10261
10262 join->limit_optimization_mode= false;
10263 join->extra_heuristic_pruning= false;
10264 join->prune_level= join->thd->variables.optimizer_prune_level;
10265
10266 if ((join->emb_sjm_nest= emb_sjm_nest))
10267 {
10268 /* We're optimizing semi-join materialization nest, so put the
10269 tables from this semi-join as first
10270 */
10271 jtab_sort_func= join_tab_cmp_embedded_first;
10272 /*
10273 If we are searching for the execution plan of a materialized semi-join
10274 nest then allowed_tables contains bits only for the tables from this
10275 nest.
10276 */
10277 join->allowed_tables= (emb_sjm_nest->sj_inner_tables &
10278 ~join->const_table_map);
10279 }
10280 else
10281 {
10282 /*
10283 if (SELECT_STRAIGHT_JOIN option is set)
10284 reorder tables so dependent tables come after tables they depend
10285 on, otherwise keep tables in the order they were specified in the query
10286 else
10287 Apply heuristic: pre-sort all access plans with respect to the number
10288 of records accessed.
10289 */
10290 jtab_sort_func= straight_join ? join_tab_cmp_straight : join_tab_cmp;
10291 join->allowed_tables= ~join->const_table_map;
10292 }
10293
10294 /*
10295 psergey-todo: if we're not optimizing an SJM nest,
10296 - sort that outer tables are first, and each sjm nest follows
10297 - then, put each [sjm_table1, ... sjm_tableN] sub-array right where
10298 WHERE clause pushdown would have put it.
10299 */
10300 my_qsort2(join->best_ref + join->const_tables,
10301 join->table_count - join->const_tables, sizeof(JOIN_TAB*),
10302 jtab_sort_func, (void*) emb_sjm_nest);
10303
10304 Json_writer_object wrapper(thd);
10305 Json_writer_array trace_plan(thd,"considered_execution_plans");
10306
10307 if (!emb_sjm_nest)
10308 choose_initial_table_order(join);

Callers 4

choose_best_splittingMethod · 0.85
make_join_statisticsFunction · 0.85
reoptimizeMethod · 0.85
optimize_semijoin_nestsFunction · 0.85

Calls 5

optimize_straight_joinFunction · 0.85
determine_search_depthFunction · 0.85
greedy_searchFunction · 0.85

Tested by

no test coverage detected