~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/optimizer/explain_plan.cc

  • Committer: Padraig O'Sullivan
  • Date: 2010-01-27 04:37:14 UTC
  • mto: This revision was merged to the branch mainline in revision 1276.
  • Revision ID: osullivan.padraig@gmail.com-20100127043714-2ahit4nj6y86y2sv
Corrected a valgrind warning due to using std::string in the Select_Lex class whose memory is
allocated on mem_root so its desctructor is never called. Created a static string array and an enum
to index into this array instead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
  "index_merge"
53
53
};
54
54
 
 
55
static const string select_type_str[]=
 
56
{
 
57
  "PRIMARY",
 
58
  "SIMPLE",
 
59
  "DERIVED",
 
60
  "DEPENDENT SUBQUERY",
 
61
  "UNCACHEABLE SUBQUERY",
 
62
  "SUBQUERY",
 
63
  "DEPENDENT UNION",
 
64
  "UNCACHEABLE_UNION",
 
65
  "UNION",
 
66
  "UNION RESULT"
 
67
};
 
68
 
55
69
void optimizer::ExplainPlan::printPlan()
56
70
{
57
71
  List<Item> field_list;
73
87
  {
74
88
    item_list.push_back(new Item_int((int32_t)
75
89
                        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(),
 
90
    item_list.push_back(new Item_string(select_type_str[join->select_lex->type].c_str(),
 
91
                                        select_type_str[join->select_lex->type].length(),
78
92
                                        cs));
79
93
    for (uint32_t i= 0; i < 7; i++)
80
94
      item_list.push_back(item_null);
100
114
    /* id */
101
115
    item_list.push_back(new Item_null);
102
116
    /* select_type */
103
 
    item_list.push_back(new Item_string(join->select_lex->type.c_str(),
104
 
                                        join->select_lex->type.length(),
 
117
    item_list.push_back(new Item_string(select_type_str[join->select_lex->type].c_str(),
 
118
                                        select_type_str[join->select_lex->type].length(),
105
119
                                        cs));
106
120
    /* table */
107
121
    {
180
194
      item_list.push_back(new Item_uint((uint32_t)
181
195
            join->select_lex->select_number));
182
196
      /* select_type */
183
 
      item_list.push_back(new Item_string(join->select_lex->type.c_str(),
184
 
                                          join->select_lex->type.length(),
 
197
      item_list.push_back(new Item_string(select_type_str[join->select_lex->type].c_str(),
 
198
                                          select_type_str[join->select_lex->type].length(),
185
199
                                          cs));
186
200
      if (tab->type == AM_ALL && tab->select && tab->select->quick)
187
201
      {
473
487
    {
474
488
      if (sl->first_inner_unit() || sl->next_select())
475
489
      {
476
 
        sl->type.assign("PRIMARY");
 
490
        sl->type= optimizer::ST_PRIMARY;
477
491
      }
478
492
      else
479
493
      {
480
 
        sl->type.assign("SIMPLE");
 
494
        sl->type= optimizer::ST_SIMPLE;
481
495
      }
482
496
    }
483
497
    else
486
500
      {
487
501
        if (sl->linkage == DERIVED_TABLE_TYPE)
488
502
        {
489
 
          sl->type.assign("DERIVED");
 
503
          sl->type= optimizer::ST_DERIVED;
490
504
        }
491
505
        else
492
506
        {
493
507
          if (uncacheable & UNCACHEABLE_DEPENDENT)
494
508
          {
495
 
            sl->type.assign("DEPENDENT SUBQUERY");
 
509
            sl->type= optimizer::ST_DEPENDENT_SUBQUERY;
496
510
          }
497
511
          else
498
512
          {
499
513
            if (uncacheable)
500
514
            {
501
 
              sl->type.assign("UNCACHEABLE SUBQUERY");
 
515
              sl->type= optimizer::ST_UNCACHEABLE_SUBQUERY;
502
516
            }
503
517
            else
504
518
            {
505
 
              sl->type.assign("SUBQUERY");
 
519
              sl->type= optimizer::ST_SUBQUERY;
506
520
            }
507
521
          }
508
522
        }
511
525
      {
512
526
        if (uncacheable & UNCACHEABLE_DEPENDENT)
513
527
        {
514
 
          sl->type.assign("DEPENDENT UNION");
 
528
          sl->type= optimizer::ST_DEPENDENT_UNION;
515
529
        }
516
530
        else
517
531
        {
518
532
          if (uncacheable)
519
533
          {
520
 
            sl->type.assign("UNCACHEABLE_UNION");
 
534
            sl->type= optimizer::ST_UNCACHEABLE_UNION;
521
535
          }
522
536
          else
523
537
          {
524
 
            sl->type.assign("UNION");
 
538
            sl->type= optimizer::ST_UNION;
525
539
          }
526
540
        }
527
541
      }
532
546
  if (unit->is_union())
533
547
  {
534
548
    unit->fake_select_lex->select_number= UINT_MAX; // just for initialization
535
 
    unit->fake_select_lex->type.assign("UNION RESULT");
 
549
    unit->fake_select_lex->type= optimizer::ST_UNION_RESULT;
536
550
    unit->fake_select_lex->options|= SELECT_DESCRIBE;
537
551
    if (! (res= unit->prepare(session, result, SELECT_NO_UNLOCK | SELECT_DESCRIBE)))
538
552
    {