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