~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/optimizer/explain_plan.cc

  • Committer: Stewart Smith
  • Date: 2010-11-07 06:43:17 UTC
  • mfrom: (1909 merge)
  • mto: This revision was merged to the branch mainline in revision 1915.
  • Revision ID: stewart@flamingspork.com-20101107064317-i0usp0cqk97ftxev
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "drizzled/session.h"
22
22
#include "drizzled/item/uint.h"
23
23
#include "drizzled/item/float.h"
 
24
#include "drizzled/item/string.h"
24
25
#include "drizzled/optimizer/explain_plan.h"
25
26
#include "drizzled/optimizer/position.h"
26
27
#include "drizzled/optimizer/quick_ror_intersect_select.h"
29
30
#include "drizzled/join.h"
30
31
#include "drizzled/internal/m_string.h"
31
32
 
 
33
#include <cstdio>
32
34
#include <string>
33
35
#include <sstream>
 
36
#include <bitset>
34
37
 
35
38
using namespace std;
36
 
using namespace drizzled;
 
39
 
 
40
namespace drizzled
 
41
{
37
42
 
38
43
static const string access_method_str[]=
39
44
{
52
57
  "index_merge"
53
58
};
54
59
 
 
60
static const string select_type_str[]=
 
61
{
 
62
  "PRIMARY",
 
63
  "SIMPLE",
 
64
  "DERIVED",
 
65
  "DEPENDENT SUBQUERY",
 
66
  "UNCACHEABLE SUBQUERY",
 
67
  "SUBQUERY",
 
68
  "DEPENDENT UNION",
 
69
  "UNCACHEABLE_UNION",
 
70
  "UNION",
 
71
  "UNION RESULT"
 
72
};
 
73
 
55
74
void optimizer::ExplainPlan::printPlan()
56
75
{
57
76
  List<Item> field_list;
73
92
  {
74
93
    item_list.push_back(new Item_int((int32_t)
75
94
                        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(),
 
95
    item_list.push_back(new Item_string(select_type_str[join->select_lex->type].c_str(),
 
96
                                        select_type_str[join->select_lex->type].length(),
78
97
                                        cs));
79
98
    for (uint32_t i= 0; i < 7; i++)
80
99
      item_list.push_back(item_null);
100
119
    /* id */
101
120
    item_list.push_back(new Item_null);
102
121
    /* select_type */
103
 
    item_list.push_back(new Item_string(join->select_lex->type.c_str(),
104
 
                                        join->select_lex->type.length(),
 
122
    item_list.push_back(new Item_string(select_type_str[join->select_lex->type].c_str(),
 
123
                                        select_type_str[join->select_lex->type].length(),
105
124
                                        cs));
106
125
    /* table */
107
126
    {
180
199
      item_list.push_back(new Item_uint((uint32_t)
181
200
            join->select_lex->select_number));
182
201
      /* select_type */
183
 
      item_list.push_back(new Item_string(join->select_lex->type.c_str(),
184
 
                                          join->select_lex->type.length(),
 
202
      item_list.push_back(new Item_string(select_type_str[join->select_lex->type].c_str(),
 
203
                                          select_type_str[join->select_lex->type].length(),
185
204
                                          cs));
186
205
      if (tab->type == AM_ALL && tab->select && tab->select->quick)
187
206
      {
217
236
      /* Build "possible_keys" value and add it to item_list */
218
237
      if (tab->keys.any())
219
238
      {
220
 
        for (uint32_t j= 0; j < table->s->keys; j++)
 
239
        for (uint32_t j= 0; j < table->getShare()->sizeKeys(); j++)
221
240
        {
222
241
          if (tab->keys.test(j))
223
242
          {
237
256
      /* Build "key", "key_len", and "ref" values and add them to item_list */
238
257
      if (tab->ref.key_parts)
239
258
      {
240
 
        KEY *key_info= table->key_info+ tab->ref.key;
 
259
        KeyInfo *key_info= table->key_info+ tab->ref.key;
241
260
        item_list.push_back(new Item_string(key_info->name,
242
261
                                            strlen(key_info->name),
243
262
                                            system_charset_info));
244
 
        uint32_t length= int64_t2str(tab->ref.key_length, keylen_str_buf, 10) -
 
263
        uint32_t length= internal::int64_t2str(tab->ref.key_length, keylen_str_buf, 10) -
245
264
                                     keylen_str_buf;
246
265
        item_list.push_back(new Item_string(keylen_str_buf, 
247
266
                                            length,
258
277
      }
259
278
      else if (tab->type == AM_NEXT)
260
279
      {
261
 
        KEY *key_info=table->key_info+ tab->index;
 
280
        KeyInfo *key_info=table->key_info+ tab->index;
262
281
        item_list.push_back(new Item_string(key_info->name,
263
282
              strlen(key_info->name),cs));
264
 
        uint32_t length= int64_t2str(key_info->key_length, keylen_str_buf, 10) -
 
283
        uint32_t length= internal::int64_t2str(key_info->key_length, keylen_str_buf, 10) -
265
284
                                     keylen_str_buf;
266
285
        item_list.push_back(new Item_string(keylen_str_buf,
267
286
                                            length,
468
487
       sl= sl->next_select())
469
488
  {
470
489
    // drop UNCACHEABLE_EXPLAIN, because it is for internal usage only
471
 
    uint8_t uncacheable= (sl->uncacheable & ~UNCACHEABLE_EXPLAIN);
 
490
    sl->uncacheable.reset(UNCACHEABLE_EXPLAIN);
472
491
    if (&session->lex->select_lex == sl)
473
492
    {
474
493
      if (sl->first_inner_unit() || sl->next_select())
475
494
      {
476
 
        sl->type.assign("PRIMARY");
 
495
        sl->type= optimizer::ST_PRIMARY;
477
496
      }
478
497
      else
479
498
      {
480
 
        sl->type.assign("SIMPLE");
 
499
        sl->type= optimizer::ST_SIMPLE;
481
500
      }
482
501
    }
483
502
    else
486
505
      {
487
506
        if (sl->linkage == DERIVED_TABLE_TYPE)
488
507
        {
489
 
          sl->type.assign("DERIVED");
 
508
          sl->type= optimizer::ST_DERIVED;
490
509
        }
491
510
        else
492
511
        {
493
 
          if (uncacheable & UNCACHEABLE_DEPENDENT)
 
512
          if (sl->uncacheable.test(UNCACHEABLE_DEPENDENT))
494
513
          {
495
 
            sl->type.assign("DEPENDENT SUBQUERY");
 
514
            sl->type= optimizer::ST_DEPENDENT_SUBQUERY;
496
515
          }
497
516
          else
498
517
          {
499
 
            if (uncacheable)
 
518
            if (sl->uncacheable.any())
500
519
            {
501
 
              sl->type.assign("UNCACHEABLE SUBQUERY");
 
520
              sl->type= optimizer::ST_UNCACHEABLE_SUBQUERY;
502
521
            }
503
522
            else
504
523
            {
505
 
              sl->type.assign("SUBQUERY");
 
524
              sl->type= optimizer::ST_SUBQUERY;
506
525
            }
507
526
          }
508
527
        }
509
528
      }
510
529
      else
511
530
      {
512
 
        if (uncacheable & UNCACHEABLE_DEPENDENT)
 
531
        if (sl->uncacheable.test(UNCACHEABLE_DEPENDENT))
513
532
        {
514
 
          sl->type.assign("DEPENDENT UNION");
 
533
          sl->type= optimizer::ST_DEPENDENT_UNION;
515
534
        }
516
535
        else
517
536
        {
518
 
          if (uncacheable)
 
537
          if (sl->uncacheable.any())
519
538
          {
520
 
            sl->type.assign("UNCACHEABLE_UNION");
 
539
            sl->type= optimizer::ST_UNCACHEABLE_UNION;
521
540
          }
522
541
          else
523
542
          {
524
 
            sl->type.assign("UNION");
 
543
            sl->type= optimizer::ST_UNION;
525
544
          }
526
545
        }
527
546
      }
532
551
  if (unit->is_union())
533
552
  {
534
553
    unit->fake_select_lex->select_number= UINT_MAX; // just for initialization
535
 
    unit->fake_select_lex->type.assign("UNION RESULT");
 
554
    unit->fake_select_lex->type= optimizer::ST_UNION_RESULT;
536
555
    unit->fake_select_lex->options|= SELECT_DESCRIBE;
537
556
    if (! (res= unit->prepare(session, result, SELECT_NO_UNLOCK | SELECT_DESCRIBE)))
538
557
    {
551
570
                      first->item_list,
552
571
                      first->where,
553
572
                      first->order_list.elements + first->group_list.elements,
554
 
                      (order_st*) first->order_list.first,
555
 
                      (order_st*) first->group_list.first,
 
573
                      (Order*) first->order_list.first,
 
574
                      (Order*) first->group_list.first,
556
575
                      first->having,
557
576
                      first->options | session->options | SELECT_DESCRIBE,
558
577
                      result, 
561
580
  }
562
581
  return (res || session->is_error());
563
582
}
 
583
 
 
584
} /* namespace drizzled */