~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/optimizer/explain_plan.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.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"
 
20
#include <config.h>
 
21
 
 
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>
32
34
 
33
35
#include <cstdio>
34
36
#include <string>
73
75
 
74
76
void optimizer::ExplainPlan::printPlan()
75
77
{
76
 
  List<Item> field_list;
77
78
  List<Item> item_list;
78
79
  Session *session= join->session;
79
80
  select_result *result= join->result;
98
99
    for (uint32_t i= 0; i < 7; i++)
99
100
      item_list.push_back(item_null);
100
101
 
101
 
    if (join->session->lex->describe & DESCRIBE_EXTENDED)
 
102
    if (join->session->getLex()->describe & DESCRIBE_EXTENDED)
102
103
      item_list.push_back(item_null);
103
104
 
104
105
    item_list.push_back(new Item_string(message,strlen(message),cs));
115
116
       appreciated :)
116
117
     */
117
118
    char table_name_buffer[NAME_LEN];
118
 
    item_list.empty();
 
119
    item_list.clear();
119
120
    /* id */
120
121
    item_list.push_back(new Item_null);
121
122
    /* select_type */
158
159
    /* ref */
159
160
    item_list.push_back(item_null);
160
161
    /* in_rows */
161
 
    if (join->session->lex->describe & DESCRIBE_EXTENDED)
 
162
    if (join->session->getLex()->describe & DESCRIBE_EXTENDED)
162
163
      item_list.push_back(item_null);
163
164
    /* rows */
164
165
    item_list.push_back(item_null);
180
181
    {
181
182
      JoinTable *tab= join->join_tab + i;
182
183
      Table *table= tab->table;
183
 
      char buff[512];
184
 
      char buff1[512], buff2[512], buff3[512];
185
184
      char keylen_str_buf[64];
186
 
      String extra(buff, sizeof(buff),cs);
 
185
      string extra;
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);
191
 
      extra.length(0);
192
 
      tmp1.length(0);
193
 
      tmp2.length(0);
194
 
      tmp3.length(0);
 
187
      string tmp1;
 
188
      string tmp2;
 
189
      string tmp3;
195
190
 
196
191
      quick_type= -1;
197
 
      item_list.empty();
 
192
      item_list.clear();
198
193
      /* id */
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))
242
237
          {
243
238
            if (tmp1.length())
244
 
              tmp1.append(',');
 
239
              tmp1.append(",");
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));
248
242
          }
249
243
        }
250
244
      }
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));
253
247
      else
254
248
        item_list.push_back(item_null);
255
249
 
268
262
        for (StoredKey **ref= tab->ref.key_copy; *ref; ref++)
269
263
        {
270
264
          if (tmp2.length())
271
 
            tmp2.append(',');
272
 
          tmp2.append((*ref)->name(), 
273
 
                       strlen((*ref)->name()),
274
 
                       system_charset_info);
 
265
            tmp2.append(",");
 
266
          tmp2.append((*ref)->name(),
 
267
                      strlen((*ref)->name()));
275
268
        }
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));
277
270
      }
278
271
      else if (tab->type == AM_NEXT)
279
272
      {
290
283
      else if (tab->select && tab->select->quick)
291
284
      {
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);
296
289
      }
297
290
      else
305
298
      double examined_rows;
306
299
      if (tab->select && tab->select->quick)
307
300
      {
308
 
        examined_rows= rows2double(tab->select->quick->records);
 
301
        examined_rows= tab->select->quick->records;
309
302
      }
310
303
      else if (tab->type == AM_NEXT || tab->type == AM_ALL)
311
304
      {
312
 
        examined_rows= rows2double(tab->limit ? tab->limit :
313
 
                                                tab->table->cursor->records());
 
305
        examined_rows= tab->limit ? tab->limit : tab->table->cursor->records();
314
306
      }
315
307
      else
316
308
      {
322
314
                                       MY_INT64_NUM_DECIMAL_DIGITS));
323
315
 
324
316
      /* Add "filtered" field to item_list. */
325
 
      if (join->session->lex->describe & DESCRIBE_EXTENDED)
 
317
      if (join->session->getLex()->describe & DESCRIBE_EXTENDED)
326
318
      {
327
319
        float f= 0.0;
328
320
        if (examined_rows)
347
339
      else if (tab->packed_info & TAB_INFO_HAVE_VALUE)
348
340
      {
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();
358
 
        if (len)
359
 
        {
360
 
          str += 2;
361
 
          len -= 2;
362
 
        }
363
 
        item_list.push_back(new Item_string(str, len, cs));
 
346
          extra.append("; Full scan on NULL key");
 
347
        if (extra.length())
 
348
          extra.erase(0, 2);        /* Skip initial "; "*/
 
349
        item_list.push_back(new Item_string(extra.c_str(), extra.length(), cs));
364
350
      }
365
351
      else
366
352
      {
374
360
            quick_type == optimizer::QuickSelectInterface::QS_TYPE_ROR_INTERSECT ||
375
361
            quick_type == optimizer::QuickSelectInterface::QS_TYPE_INDEX_MERGE)
376
362
        {
377
 
          extra.append(STRING_WITH_LEN("; Using "));
 
363
          extra.append("; Using ");
378
364
          tab->select->quick->add_info_string(&extra);
379
365
        }
380
366
        if (tab->select)
399
385
              if (tmp.any())
400
386
                s << uppercase << hex << tmp.to_ulong();
401
387
            }
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());
405
 
            extra.append(')');
 
390
            extra.append(")");
406
391
          }
407
392
          else if (tab->select->cond)
408
393
          {
409
 
            extra.append(STRING_WITH_LEN("; Using where"));
 
394
            extra.append("; Using where");
410
395
          }
411
396
        }
412
397
        if (key_read)
413
398
        {
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");
416
401
          else
417
 
            extra.append(STRING_WITH_LEN("; Using index"));
 
402
            extra.append("; Using index");
418
403
        }
419
404
        if (table->reginfo.not_exists_optimize)
420
 
          extra.append(STRING_WITH_LEN("; Not exists"));
 
405
          extra.append("; Not exists");
421
406
 
422
407
        if (need_tmp_table)
423
408
        {
424
409
          need_tmp_table=0;
425
 
          extra.append(STRING_WITH_LEN("; Using temporary"));
 
410
          extra.append("; Using temporary");
426
411
        }
427
412
        if (need_order)
428
413
        {
429
414
          need_order=0;
430
 
          extra.append(STRING_WITH_LEN("; Using filesort"));
 
415
          extra.append("; Using filesort");
431
416
        }
432
417
        if (distinct & test_all_bits(used_tables,session->used_tables))
433
 
          extra.append(STRING_WITH_LEN("; Distinct"));
 
418
          extra.append("; Distinct");
434
419
 
435
420
        if (tab->insideout_match_tab)
436
421
        {
437
 
          extra.append(STRING_WITH_LEN("; LooseScan"));
 
422
          extra.append("; LooseScan");
438
423
        }
439
424
 
440
425
        for (uint32_t part= 0; part < tab->ref.key_parts; part++)
441
426
        {
442
427
          if (tab->ref.cond_guards[part])
443
428
          {
444
 
            extra.append(STRING_WITH_LEN("; Full scan on NULL key"));
 
429
            extra.append("; Full scan on NULL key");
445
430
            break;
446
431
          }
447
432
        }
448
433
 
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");
451
436
 
452
 
        /* Skip initial "; "*/
453
 
        const char *str= extra.ptr();
454
 
        uint32_t len= extra.length();
455
 
        if (len)
456
 
        {
457
 
          str += 2;
458
 
          len -= 2;
459
 
        }
460
 
        item_list.push_back(new Item_string(str, len, cs));
 
437
        if (extra.length())
 
438
          extra.erase(0, 2);
 
439
        item_list.push_back(new Item_string(extra.c_str(), extra.length(), cs));
461
440
      }
462
441
      // For next iteration
463
442
      used_tables|=table->map;
488
467
  {
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)
492
471
    {
493
472
      if (sl->first_inner_unit() || sl->next_select())
494
473
      {
561
540
  }
562
541
  else
563
542
  {
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,