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

Function choose_initial_table_order

sql/sql_select.cc:10156–10228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10154*/
10155
10156static void choose_initial_table_order(JOIN *join)
10157{
10158 TABLE_LIST *emb_subq;
10159 JOIN_TAB **tab= join->best_ref + join->const_tables;
10160 JOIN_TAB **tabs_end= tab + join->table_count - join->const_tables;
10161 DBUG_ENTER("choose_initial_table_order");
10162
10163 /* Find where the top-level JOIN_TABs end and subquery JOIN_TABs start */
10164 for (; tab != tabs_end; tab++)
10165 {
10166 if ((emb_subq= get_emb_subq(*tab)))
10167 break;
10168 }
10169 uint n_subquery_tabs= (uint)(tabs_end - tab);
10170
10171 if (!n_subquery_tabs)
10172 DBUG_VOID_RETURN;
10173
10174 /* Copy the subquery JOIN_TABs to a separate array */
10175 JOIN_TAB *subquery_tabs[MAX_TABLES];
10176 memcpy(subquery_tabs, tab, sizeof(JOIN_TAB*) * n_subquery_tabs);
10177
10178 JOIN_TAB **last_top_level_tab= tab;
10179 JOIN_TAB **subq_tab= subquery_tabs;
10180 JOIN_TAB **subq_tabs_end= subquery_tabs + n_subquery_tabs;
10181 TABLE_LIST *cur_subq_nest= NULL;
10182 for (; subq_tab < subq_tabs_end; subq_tab++)
10183 {
10184 if (get_emb_subq(*subq_tab)!= cur_subq_nest)
10185 {
10186 /*
10187 Reached the part of subquery_tabs that covers tables in some subquery.
10188 */
10189 cur_subq_nest= get_emb_subq(*subq_tab);
10190
10191 /* Determine how many tables the subquery has */
10192 JOIN_TAB **last_tab_for_subq;
10193 for (last_tab_for_subq= subq_tab;
10194 last_tab_for_subq < subq_tabs_end &&
10195 get_emb_subq(*last_tab_for_subq) == cur_subq_nest;
10196 last_tab_for_subq++) {}
10197 uint n_subquery_tables= (uint)(last_tab_for_subq - subq_tab);
10198
10199 /*
10200 Walk the original array and find where this subquery would have been
10201 attached to
10202 */
10203 table_map need_tables= cur_subq_nest->original_subq_pred_used_tables;
10204 need_tables &= ~(join->const_table_map | PSEUDO_TABLE_BITS);
10205 for (JOIN_TAB **top_level_tab= join->best_ref + join->const_tables;
10206 top_level_tab < last_top_level_tab;
10207 //top_level_tab < join->best_ref + join->table_count;
10208 top_level_tab++)
10209 {
10210 need_tables &= ~(*top_level_tab)->table->map;
10211 /* Check if this is the place where subquery should be attached */
10212 if (!need_tables)
10213 {

Callers 1

choose_planFunction · 0.85

Calls 1

get_emb_subqFunction · 0.85

Tested by

no test coverage detected