~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/optimizer/explain_plan.cc

Merged remove-dead-Item-save_in_field_no_warnings into fix-order_st-BY-comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include <sstream>
34
34
 
35
35
using namespace std;
36
 
using namespace drizzled;
 
36
 
 
37
namespace drizzled
 
38
{
37
39
 
38
40
static const string access_method_str[]=
39
41
{
52
54
  "index_merge"
53
55
};
54
56
 
 
57
static const string select_type_str[]=
 
58
{
 
59
  "PRIMARY",
 
60
  "SIMPLE",
 
61
  "DERIVED",
 
62
  "DEPENDENT SUBQUERY",
 
63
  "UNCACHEABLE SUBQUERY",
 
64
  "SUBQUERY",
 
65
  "DEPENDENT UNION",
 
66
  "UNCACHEABLE_UNION",
 
67
  "UNION",
 
68
  "UNION RESULT"
 
69
};
 
70
 
55
71
void optimizer::ExplainPlan::printPlan()
56
72
{
57
73
  List<Item> field_list;
73
89
  {
74
90
    item_list.push_back(new Item_int((int32_t)
75
91
                        join->select_lex->select_number));
76
 
    item_list.push_back(new Item_string(join->select_lex->type.c_str(),
77
 
                                        join->select_lex->type.length(),
 
92
    item_list.push_back(new Item_string(select_type_str[join->select_lex->type].c_str(),
 
93
                                        select_type_str[join->select_lex->type].length(),
78
94
                                        cs));
79
95
    for (uint32_t i= 0; i < 7; i++)
80
96
      item_list.push_back(item_null);
100
116
    /* id */
101
117
    item_list.push_back(new Item_null);
102
118
    /* select_type */
103
 
    item_list.push_back(new Item_string(join->select_lex->type.c_str(),
104
 
                                        join->select_lex->type.length(),
 
119
    item_list.push_back(new Item_string(select_type_str[join->select_lex->type].c_str(),
 
120
                                        select_type_str[join->select_lex->type].length(),
105
121
                                        cs));
106
122
    /* table */
107
123
    {
180
196
      item_list.push_back(new Item_uint((uint32_t)
181
197
            join->select_lex->select_number));
182
198
      /* select_type */
183
 
      item_list.push_back(new Item_string(join->select_lex->type.c_str(),
184
 
                                          join->select_lex->type.length(),
 
199
      item_list.push_back(new Item_string(select_type_str[join->select_lex->type].c_str(),
 
200
                                          select_type_str[join->select_lex->type].length(),
185
201
                                          cs));
186
202
      if (tab->type == AM_ALL && tab->select && tab->select->quick)
187
203
      {
241
257
        item_list.push_back(new Item_string(key_info->name,
242
258
                                            strlen(key_info->name),
243
259
                                            system_charset_info));
244
 
        uint32_t length= int64_t2str(tab->ref.key_length, keylen_str_buf, 10) -
 
260
        uint32_t length= internal::int64_t2str(tab->ref.key_length, keylen_str_buf, 10) -
245
261
                                     keylen_str_buf;
246
262
        item_list.push_back(new Item_string(keylen_str_buf, 
247
263
                                            length,
261
277
        KEY *key_info=table->key_info+ tab->index;
262
278
        item_list.push_back(new Item_string(key_info->name,
263
279
              strlen(key_info->name),cs));
264
 
        uint32_t length= int64_t2str(key_info->key_length, keylen_str_buf, 10) -
 
280
        uint32_t length= internal::int64_t2str(key_info->key_length, keylen_str_buf, 10) -
265
281
                                     keylen_str_buf;
266
282
        item_list.push_back(new Item_string(keylen_str_buf,
267
283
                                            length,
473
489
    {
474
490
      if (sl->first_inner_unit() || sl->next_select())
475
491
      {
476
 
        sl->type.assign("PRIMARY");
 
492
        sl->type= optimizer::ST_PRIMARY;
477
493
      }
478
494
      else
479
495
      {
480
 
        sl->type.assign("SIMPLE");
 
496
        sl->type= optimizer::ST_SIMPLE;
481
497
      }
482
498
    }
483
499
    else
486
502
      {
487
503
        if (sl->linkage == DERIVED_TABLE_TYPE)
488
504
        {
489
 
          sl->type.assign("DERIVED");
 
505
          sl->type= optimizer::ST_DERIVED;
490
506
        }
491
507
        else
492
508
        {
493
509
          if (uncacheable & UNCACHEABLE_DEPENDENT)
494
510
          {
495
 
            sl->type.assign("DEPENDENT SUBQUERY");
 
511
            sl->type= optimizer::ST_DEPENDENT_SUBQUERY;
496
512
          }
497
513
          else
498
514
          {
499
515
            if (uncacheable)
500
516
            {
501
 
              sl->type.assign("UNCACHEABLE SUBQUERY");
 
517
              sl->type= optimizer::ST_UNCACHEABLE_SUBQUERY;
502
518
            }
503
519
            else
504
520
            {
505
 
              sl->type.assign("SUBQUERY");
 
521
              sl->type= optimizer::ST_SUBQUERY;
506
522
            }
507
523
          }
508
524
        }
511
527
      {
512
528
        if (uncacheable & UNCACHEABLE_DEPENDENT)
513
529
        {
514
 
          sl->type.assign("DEPENDENT UNION");
 
530
          sl->type= optimizer::ST_DEPENDENT_UNION;
515
531
        }
516
532
        else
517
533
        {
518
534
          if (uncacheable)
519
535
          {
520
 
            sl->type.assign("UNCACHEABLE_UNION");
 
536
            sl->type= optimizer::ST_UNCACHEABLE_UNION;
521
537
          }
522
538
          else
523
539
          {
524
 
            sl->type.assign("UNION");
 
540
            sl->type= optimizer::ST_UNION;
525
541
          }
526
542
        }
527
543
      }
532
548
  if (unit->is_union())
533
549
  {
534
550
    unit->fake_select_lex->select_number= UINT_MAX; // just for initialization
535
 
    unit->fake_select_lex->type.assign("UNION RESULT");
 
551
    unit->fake_select_lex->type= optimizer::ST_UNION_RESULT;
536
552
    unit->fake_select_lex->options|= SELECT_DESCRIBE;
537
553
    if (! (res= unit->prepare(session, result, SELECT_NO_UNLOCK | SELECT_DESCRIBE)))
538
554
    {
561
577
  }
562
578
  return (res || session->is_error());
563
579
}
 
580
 
 
581
} /* namespace drizzled */