| 6121 | } |
| 6122 | |
| 6123 | static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables) |
| 6124 | { |
| 6125 | LEX *lex= thd->lex; |
| 6126 | select_result *result=lex->result; |
| 6127 | bool res; |
| 6128 | /* assign global limit variable if limit is not given */ |
| 6129 | { |
| 6130 | SELECT_LEX *param= lex->unit.global_parameters(); |
| 6131 | if (!param->limit_params.explicit_limit) |
| 6132 | param->limit_params.select_limit= |
| 6133 | new (thd->mem_root) Item_int(thd, |
| 6134 | (ulonglong) thd->variables.select_limit); |
| 6135 | } |
| 6136 | |
| 6137 | if (!(res= open_and_lock_tables(thd, all_tables, TRUE, 0))) |
| 6138 | { |
| 6139 | lex->resolve_optimizer_hints(); |
| 6140 | if (lex->describe) |
| 6141 | { |
| 6142 | /* |
| 6143 | We always use select_send for EXPLAIN, even if it's an EXPLAIN |
| 6144 | for SELECT ... INTO OUTFILE: a user application should be able |
| 6145 | to prepend EXPLAIN to any query and receive output for it, |
| 6146 | even if the query itself redirects the output. |
| 6147 | */ |
| 6148 | if (unlikely(!(result= new (thd->mem_root) select_send(thd)))) |
| 6149 | return 1; /* purecov: inspected */ |
| 6150 | thd->send_explain_fields(result, lex->describe, lex->analyze_stmt); |
| 6151 | |
| 6152 | /* |
| 6153 | This will call optimize() for all parts of query. The query plan is |
| 6154 | printed out below. |
| 6155 | */ |
| 6156 | res= mysql_explain_union(thd, &lex->unit, result); |
| 6157 | |
| 6158 | /* Print EXPLAIN only if we don't have an error */ |
| 6159 | if (likely(!res)) |
| 6160 | { |
| 6161 | /* |
| 6162 | Do like the original select_describe did: remove OFFSET from the |
| 6163 | top-level LIMIT |
| 6164 | */ |
| 6165 | result->remove_offset_limit(); |
| 6166 | if (lex->explain_json) |
| 6167 | { |
| 6168 | lex->explain->print_explain_json(result, lex->analyze_stmt); |
| 6169 | } |
| 6170 | else |
| 6171 | { |
| 6172 | lex->explain->print_explain(result, thd->lex->describe, |
| 6173 | thd->lex->analyze_stmt); |
| 6174 | if (lex->describe & DESCRIBE_EXTENDED) |
| 6175 | { |
| 6176 | char buff[1024]; |
| 6177 | String str(buff,(uint32) sizeof(buff), system_charset_info); |
| 6178 | str.length(0); |
| 6179 | /* |
| 6180 | The warnings system requires input in utf8, @see |
no test coverage detected