~posulliv/drizzle/optimizer-style-cleanup

« back to all changes in this revision

Viewing changes to plugin/schema_dictionary/show_indexes.cc

  • Committer: Padraig O'Sullivan
  • Date: 2010-03-15 14:05:26 UTC
  • mfrom: (1237.9.99 staging)
  • Revision ID: osullivan.padraig@gmail.com-20100315140526-opbgwdwn6tfecdkq
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2010 Brian Aker
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
#include "plugin/schema_dictionary/dictionary.h"
 
23
#include "drizzled/table_identifier.h"
 
24
 
 
25
 
 
26
using namespace std;
 
27
using namespace drizzled;
 
28
 
 
29
ShowIndexes::ShowIndexes() :
 
30
  plugin::TableFunction("DATA_DICTIONARY", "SHOW_INDEXES")
 
31
{
 
32
  add_field("Table");
 
33
  add_field("Unique", plugin::TableFunction::BOOLEAN);
 
34
  add_field("Key_name");
 
35
  add_field("Seq_in_index", plugin::TableFunction::NUMBER);
 
36
  add_field("Column_name");
 
37
}
 
38
 
 
39
ShowIndexes::Generator::Generator(Field **arg) :
 
40
  plugin::TableFunction::Generator(arg),
 
41
  is_tables_primed(false),
 
42
  is_index_primed(false),
 
43
  is_index_part_primed(false),
 
44
  index_iterator(0),
 
45
  index_part_iterator(0)
 
46
{
 
47
  Session *session= current_session;
 
48
  statement::Select *select= static_cast<statement::Select *>(session->lex->statement);
 
49
 
 
50
  table_name.append(select->getShowTable().c_str());
 
51
  TableIdentifier identifier(select->getShowSchema().c_str(), select->getShowTable().c_str());
 
52
 
 
53
  is_tables_primed= plugin::StorageEngine::getTableDefinition(*session,
 
54
                                                              identifier,
 
55
                                                              &table_proto);
 
56
}
 
57
 
 
58
bool ShowIndexes::Generator::nextIndexCore()
 
59
{
 
60
  if (isIndexesPrimed())
 
61
  {
 
62
    index_iterator++;
 
63
  }
 
64
  else
 
65
  {
 
66
    if (not isTablesPrimed())
 
67
      return false;
 
68
 
 
69
    index_iterator= 0;
 
70
    is_index_primed= true;
 
71
  }
 
72
 
 
73
  if (index_iterator >= getTableProto().indexes_size())
 
74
    return false;
 
75
 
 
76
  index= getTableProto().indexes(index_iterator);
 
77
 
 
78
  return true;
 
79
}
 
80
 
 
81
bool ShowIndexes::Generator::nextIndex()
 
82
{
 
83
  while (not nextIndexCore())
 
84
  {
 
85
    return false;
 
86
  }
 
87
 
 
88
  return true;
 
89
}
 
90
 
 
91
bool ShowIndexes::Generator::nextIndexPartsCore()
 
92
{
 
93
  if (is_index_part_primed)
 
94
  {
 
95
    index_part_iterator++;
 
96
  }
 
97
  else
 
98
  {
 
99
    if (not isIndexesPrimed())
 
100
      return false;
 
101
 
 
102
    index_part_iterator= 0;
 
103
    is_index_part_primed= true;
 
104
  }
 
105
 
 
106
  if (index_part_iterator >= getIndex().index_part_size())
 
107
    return false;
 
108
 
 
109
  index_part= getIndex().index_part(index_part_iterator);
 
110
 
 
111
  return true;
 
112
}
 
113
 
 
114
 
 
115
bool ShowIndexes::Generator::nextIndexParts()
 
116
{
 
117
  while (not nextIndexPartsCore())
 
118
  {
 
119
    if (not nextIndex())
 
120
      return false;
 
121
    is_index_part_primed= false;
 
122
  }
 
123
 
 
124
  return true;
 
125
}
 
126
 
 
127
 
 
128
 
 
129
bool ShowIndexes::Generator::populate()
 
130
{
 
131
  if (not nextIndexParts())
 
132
    return false;
 
133
 
 
134
  fill();
 
135
 
 
136
  return true;
 
137
}
 
138
 
 
139
void ShowIndexes::Generator::fill()
 
140
{
 
141
  /* Table */
 
142
  push(getTableName());
 
143
 
 
144
  /* Unique */
 
145
  push(getIndex().is_unique());
 
146
 
 
147
  /* Key_name */
 
148
  push(getIndex().name());
 
149
 
 
150
  /* Seq_in_index */
 
151
  push(static_cast<int64_t>(index_part_iterator + 1));
 
152
 
 
153
  /* Column_name */
 
154
  push(getTableProto().field(getIndexPart().fieldnr()).name());
 
155
}