17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include <drizzled/session.h>
23
#include <drizzled/item/uint.h>
24
#include <drizzled/item/float.h>
25
#include <drizzled/item/string.h>
26
#include <drizzled/optimizer/explain_plan.h>
27
#include <drizzled/optimizer/position.h>
28
#include <drizzled/optimizer/quick_ror_intersect_select.h>
29
#include <drizzled/optimizer/range.h>
30
#include <drizzled/sql_select.h>
31
#include <drizzled/join.h>
32
#include <drizzled/internal/m_string.h>
33
#include <drizzled/select_result.h>
21
#include "drizzled/session.h"
22
#include "drizzled/item/uint.h"
23
#include "drizzled/item/float.h"
24
#include "drizzled/item/string.h"
25
#include "drizzled/optimizer/explain_plan.h"
26
#include "drizzled/optimizer/position.h"
27
#include "drizzled/optimizer/quick_ror_intersect_select.h"
28
#include "drizzled/optimizer/range.h"
29
#include "drizzled/sql_select.h"
30
#include "drizzled/join.h"
31
#include "drizzled/internal/m_string.h"
99
98
for (uint32_t i= 0; i < 7; i++)
100
99
item_list.push_back(item_null);
102
if (join->session->getLex()->describe & DESCRIBE_EXTENDED)
101
if (join->session->lex->describe & DESCRIBE_EXTENDED)
103
102
item_list.push_back(item_null);
105
104
item_list.push_back(new Item_string(message,strlen(message),cs));
160
159
item_list.push_back(item_null);
162
if (join->session->getLex()->describe & DESCRIBE_EXTENDED)
161
if (join->session->lex->describe & DESCRIBE_EXTENDED)
163
162
item_list.push_back(item_null);
165
164
item_list.push_back(item_null);
182
181
JoinTable *tab= join->join_tab + i;
183
182
Table *table= tab->table;
184
char buff1[512], buff2[512], buff3[512];
184
185
char keylen_str_buf[64];
186
String extra(buff, sizeof(buff),cs);
186
187
char table_name_buffer[NAME_LEN];
188
String tmp1(buff1,sizeof(buff1),cs);
189
String tmp2(buff2,sizeof(buff2),cs);
190
String tmp3(buff3,sizeof(buff3),cs);
194
199
item_list.push_back(new Item_uint((uint32_t)
195
200
join->select_lex->select_number));
236
241
if (tab->keys.test(j))
238
243
if (tmp1.length())
240
245
tmp1.append(table->key_info[j].name,
241
strlen(table->key_info[j].name));
246
strlen(table->key_info[j].name),
247
system_charset_info);
245
251
if (tmp1.length())
246
item_list.push_back(new Item_string(tmp1.c_str(),tmp1.length(),cs));
252
item_list.push_back(new Item_string(tmp1.ptr(),tmp1.length(),cs));
248
254
item_list.push_back(item_null);
262
268
for (StoredKey **ref= tab->ref.key_copy; *ref; ref++)
264
270
if (tmp2.length())
266
tmp2.append((*ref)->name(),
267
strlen((*ref)->name()));
272
tmp2.append((*ref)->name(),
273
strlen((*ref)->name()),
274
system_charset_info);
269
item_list.push_back(new Item_string(tmp2.c_str(),tmp2.length(),cs));
276
item_list.push_back(new Item_string(tmp2.ptr(),tmp2.length(),cs));
271
278
else if (tab->type == AM_NEXT)
283
290
else if (tab->select && tab->select->quick)
285
292
tab->select->quick->add_keys_and_lengths(&tmp2, &tmp3);
286
item_list.push_back(new Item_string(tmp2.c_str(),tmp2.length(),cs));
287
item_list.push_back(new Item_string(tmp3.c_str(),tmp3.length(),cs));
293
item_list.push_back(new Item_string(tmp2.ptr(),tmp2.length(),cs));
294
item_list.push_back(new Item_string(tmp3.ptr(),tmp3.length(),cs));
288
295
item_list.push_back(item_null);
298
305
double examined_rows;
299
306
if (tab->select && tab->select->quick)
301
examined_rows= tab->select->quick->records;
308
examined_rows= rows2double(tab->select->quick->records);
303
310
else if (tab->type == AM_NEXT || tab->type == AM_ALL)
305
examined_rows= tab->limit ? tab->limit : tab->table->cursor->records();
312
examined_rows= rows2double(tab->limit ? tab->limit :
313
tab->table->cursor->records());
339
347
else if (tab->packed_info & TAB_INFO_HAVE_VALUE)
341
349
if (tab->packed_info & TAB_INFO_USING_INDEX)
342
extra.append("; Using index");
350
extra.append(STRING_WITH_LEN("; Using index"));
343
351
if (tab->packed_info & TAB_INFO_USING_WHERE)
344
extra.append("; Using where");
352
extra.append(STRING_WITH_LEN("; Using where"));
345
353
if (tab->packed_info & TAB_INFO_FULL_SCAN_ON_NULL)
346
extra.append("; Full scan on NULL key");
348
extra.erase(0, 2); /* Skip initial "; "*/
349
item_list.push_back(new Item_string(extra.c_str(), extra.length(), cs));
354
extra.append(STRING_WITH_LEN("; Full scan on NULL key"));
355
/* Skip initial "; "*/
356
const char *str= extra.ptr();
357
uint32_t len= extra.length();
363
item_list.push_back(new Item_string(str, len, cs));
360
374
quick_type == optimizer::QuickSelectInterface::QS_TYPE_ROR_INTERSECT ||
361
375
quick_type == optimizer::QuickSelectInterface::QS_TYPE_INDEX_MERGE)
363
extra.append("; Using ");
377
extra.append(STRING_WITH_LEN("; Using "));
364
378
tab->select->quick->add_info_string(&extra);
386
400
s << uppercase << hex << tmp.to_ulong();
388
extra.append("; Range checked for each record (index map: 0x");
402
extra.append(STRING_WITH_LEN("; Range checked for each "
403
"record (index map: 0x"));
389
404
extra.append(s.str().c_str());
392
407
else if (tab->select->cond)
394
extra.append("; Using where");
409
extra.append(STRING_WITH_LEN("; Using where"));
399
414
if (quick_type == optimizer::QuickSelectInterface::QS_TYPE_GROUP_MIN_MAX)
400
extra.append("; Using index for group-by");
415
extra.append(STRING_WITH_LEN("; Using index for group-by"));
402
extra.append("; Using index");
417
extra.append(STRING_WITH_LEN("; Using index"));
404
419
if (table->reginfo.not_exists_optimize)
405
extra.append("; Not exists");
420
extra.append(STRING_WITH_LEN("; Not exists"));
407
422
if (need_tmp_table)
409
424
need_tmp_table=0;
410
extra.append("; Using temporary");
425
extra.append(STRING_WITH_LEN("; Using temporary"));
415
extra.append("; Using filesort");
430
extra.append(STRING_WITH_LEN("; Using filesort"));
417
432
if (distinct & test_all_bits(used_tables,session->used_tables))
418
extra.append("; Distinct");
433
extra.append(STRING_WITH_LEN("; Distinct"));
420
435
if (tab->insideout_match_tab)
422
extra.append("; LooseScan");
437
extra.append(STRING_WITH_LEN("; LooseScan"));
425
440
for (uint32_t part= 0; part < tab->ref.key_parts; part++)
427
442
if (tab->ref.cond_guards[part])
429
extra.append("; Full scan on NULL key");
444
extra.append(STRING_WITH_LEN("; Full scan on NULL key"));
434
449
if (i > 0 && tab[-1].next_select == sub_select_cache)
435
extra.append("; Using join buffer");
450
extra.append(STRING_WITH_LEN("; Using join buffer"));
439
item_list.push_back(new Item_string(extra.c_str(), extra.length(), cs));
452
/* Skip initial "; "*/
453
const char *str= extra.ptr();
454
uint32_t len= extra.length();
460
item_list.push_back(new Item_string(str, len, cs));
441
462
// For next iteration
442
463
used_tables|=table->map;
468
489
// drop UNCACHEABLE_EXPLAIN, because it is for internal usage only
469
490
sl->uncacheable.reset(UNCACHEABLE_EXPLAIN);
470
if (&session->getLex()->select_lex == sl)
491
if (&session->lex->select_lex == sl)
472
493
if (sl->first_inner_unit() || sl->next_select())
543
session->getLex()->current_select= first;
564
session->lex->current_select= first;
544
565
unit->set_limit(unit->global_parameters);
545
566
res= select_query(session,
546
567
&first->ref_pointer_array,