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

Method optimize

sql/sql_union.cc:2230–2334  ·  view source on GitHub ↗

Run optimization phase. @return false unit successfully passed optimization phase. @return TRUE an error occur. */

Source from the content-addressed store, hash-verified

2228 @return TRUE an error occur.
2229*/
2230bool st_select_lex_unit::optimize()
2231{
2232 SELECT_LEX *lex_select_save= thd->lex->current_select;
2233 SELECT_LEX *select_cursor=first_select();
2234 DBUG_ENTER("st_select_lex_unit::optimize");
2235
2236 if (optimized && !uncacheable && !describe)
2237 DBUG_RETURN(false);
2238
2239 if (with_element && with_element->is_recursive && optimize_started)
2240 DBUG_RETURN(false);
2241 optimize_started= true;
2242
2243 if (uncacheable || !item || !item->assigned() || describe)
2244 {
2245 if (item)
2246 item->reset_value_registration();
2247 if (optimized && item)
2248 {
2249 if (item->assigned())
2250 {
2251 item->assigned(0); // We will reinit & reexecute unit
2252 item->reset();
2253 }
2254 if (table->is_created())
2255 {
2256 table->file->ha_delete_all_rows();
2257 table->file->info(HA_STATUS_VARIABLE);
2258 }
2259 /* re-enabling indexes for next subselect iteration */
2260 if ((union_result->force_enable_index_if_needed() || union_distinct))
2261 {
2262 if(table->file->ha_enable_indexes(key_map(table->s->keys), false))
2263 DBUG_ASSERT(0);
2264 else
2265 table->no_keyread= 0;
2266 }
2267 }
2268 for (SELECT_LEX *sl= select_cursor; sl; sl= sl->next_select())
2269 {
2270 if (sl->tvc)
2271 {
2272 sl->tvc->select_options=
2273 (lim.is_unlimited() || sl->braces) ?
2274 sl->options & ~OPTION_FOUND_ROWS : sl->options | found_rows_for_union;
2275 if (sl->tvc->optimize(thd))
2276 {
2277 thd->lex->current_select= lex_select_save;
2278 DBUG_RETURN(TRUE);
2279 }
2280 if (derived)
2281 sl->increase_derived_records(sl->tvc->get_records());
2282 continue;
2283 }
2284 thd->lex->current_select= sl;
2285
2286 if (optimized)
2287 saved_error= sl->join->reinit();

Callers 1

exec_innerMethod · 0.45

Calls 15

assignedMethod · 0.80
ha_delete_all_rowsMethod · 0.80
ha_enable_indexesMethod · 0.80
next_selectMethod · 0.80
is_unlimitedMethod · 0.80
get_recordsMethod · 0.80
remove_offsetMethod · 0.80
set_unlimitedMethod · 0.80
resetMethod · 0.45

Tested by

no test coverage detected