1309.2.3
by Brian Aker
Update the code so use a faster index lookup method. |
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 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
21 |
#include <config.h> |
22 |
#include <plugin/show_dictionary/dictionary.h> |
|
23 |
#include <drizzled/identifier.h> |
|
1309.2.3
by Brian Aker
Update the code so use a faster index lookup method. |
24 |
|
25 |
||
26 |
using namespace std; |
|
27 |
using namespace drizzled; |
|
28 |
||
29 |
ShowIndexes::ShowIndexes() : |
|
1874.2.4
by Brian Aker
Have show functions be invisible. |
30 |
show_dictionary::Show("SHOW_INDEXES") |
1309.2.3
by Brian Aker
Update the code so use a faster index lookup method. |
31 |
{
|
32 |
add_field("Table"); |
|
1643.3.10
by Brian Aker
Column support, clean up of IS/DD for NULL type. |
33 |
add_field("Unique", plugin::TableFunction::BOOLEAN, 0, false); |
1309.2.3
by Brian Aker
Update the code so use a faster index lookup method. |
34 |
add_field("Key_name"); |
1643.3.10
by Brian Aker
Column support, clean up of IS/DD for NULL type. |
35 |
add_field("Seq_in_index", plugin::TableFunction::NUMBER, 0, false); |
1309.2.3
by Brian Aker
Update the code so use a faster index lookup method. |
36 |
add_field("Column_name"); |
37 |
}
|
|
38 |
||
39 |
ShowIndexes::Generator::Generator(Field **arg) : |
|
1874.2.4
by Brian Aker
Have show functions be invisible. |
40 |
show_dictionary::Show::Generator(arg), |
1309.2.3
by Brian Aker
Update the code so use a faster index lookup method. |
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 |
{
|
|
2059.1.1
by Andrew Hutchings
Refix show_dictionary plugin crash when not using 'SHOW' to access. |
47 |
if (not isShowQuery()) |
48 |
return; |
|
49 |
||
2227.4.7
by Olaf van der Spek
plugin::TableFunction::Generator::statement() |
50 |
statement::Show& select= static_cast<statement::Show&>(statement()); |
1309.2.3
by Brian Aker
Update the code so use a faster index lookup method. |
51 |
|
2227.4.7
by Olaf van der Spek
plugin::TableFunction::Generator::statement() |
52 |
if (not select.getShowTable().empty() && not select.getShowSchema().empty()) |
1448
by Brian Aker
Fix for bug on show tables.:w |
53 |
{
|
2227.4.7
by Olaf van der Spek
plugin::TableFunction::Generator::statement() |
54 |
table_name.append(select.getShowTable().c_str()); |
55 |
identifier::Table identifier(select.getShowSchema().c_str(), select.getShowTable().c_str()); |
|
1309.2.3
by Brian Aker
Update the code so use a faster index lookup method. |
56 |
|
2179.6.10
by Stewart Smith
add authorization check to SHOW INDEXES |
57 |
if (not plugin::Authorization::isAuthorized(*getSession().user(), |
58 |
identifier, false)) |
|
59 |
{
|
|
60 |
drizzled::error::access(*getSession().user(), identifier); |
|
61 |
return; |
|
62 |
}
|
|
63 |
||
2159.2.4
by Brian Aker
Merge in error wasteful removal. |
64 |
table_proto= plugin::StorageEngine::getTableMessage(getSession(), identifier); |
2159.2.3
by Brian Aker
Remove dead call for getTableMessage() |
65 |
|
66 |
if (table_proto) |
|
67 |
is_tables_primed= true; |
|
1448
by Brian Aker
Fix for bug on show tables.:w |
68 |
}
|
1309.2.3
by Brian Aker
Update the code so use a faster index lookup method. |
69 |
}
|
70 |
||
71 |
bool ShowIndexes::Generator::nextIndexCore() |
|
72 |
{
|
|
73 |
if (isIndexesPrimed()) |
|
74 |
{
|
|
75 |
index_iterator++; |
|
76 |
}
|
|
77 |
else
|
|
78 |
{
|
|
79 |
if (not isTablesPrimed()) |
|
80 |
return false; |
|
81 |
||
82 |
index_iterator= 0; |
|
83 |
is_index_primed= true; |
|
84 |
}
|
|
85 |
||
86 |
if (index_iterator >= getTableProto().indexes_size()) |
|
87 |
return false; |
|
88 |
||
89 |
index= getTableProto().indexes(index_iterator); |
|
90 |
||
91 |
return true; |
|
92 |
}
|
|
93 |
||
94 |
bool ShowIndexes::Generator::nextIndex() |
|
95 |
{
|
|
96 |
while (not nextIndexCore()) |
|
97 |
{
|
|
98 |
return false; |
|
99 |
}
|
|
100 |
||
101 |
return true; |
|
102 |
}
|
|
103 |
||
104 |
bool ShowIndexes::Generator::nextIndexPartsCore() |
|
105 |
{
|
|
106 |
if (is_index_part_primed) |
|
107 |
{
|
|
108 |
index_part_iterator++; |
|
109 |
}
|
|
110 |
else
|
|
111 |
{
|
|
112 |
if (not isIndexesPrimed()) |
|
113 |
return false; |
|
114 |
||
115 |
index_part_iterator= 0; |
|
116 |
is_index_part_primed= true; |
|
117 |
}
|
|
118 |
||
119 |
if (index_part_iterator >= getIndex().index_part_size()) |
|
120 |
return false; |
|
121 |
||
122 |
index_part= getIndex().index_part(index_part_iterator); |
|
123 |
||
124 |
return true; |
|
125 |
}
|
|
126 |
||
127 |
||
128 |
bool ShowIndexes::Generator::nextIndexParts() |
|
129 |
{
|
|
130 |
while (not nextIndexPartsCore()) |
|
131 |
{
|
|
132 |
if (not nextIndex()) |
|
133 |
return false; |
|
134 |
is_index_part_primed= false; |
|
135 |
}
|
|
136 |
||
137 |
return true; |
|
138 |
}
|
|
139 |
||
140 |
||
141 |
||
142 |
bool ShowIndexes::Generator::populate() |
|
143 |
{
|
|
144 |
if (not nextIndexParts()) |
|
145 |
return false; |
|
146 |
||
147 |
fill(); |
|
148 |
||
149 |
return true; |
|
150 |
}
|
|
151 |
||
152 |
void ShowIndexes::Generator::fill() |
|
153 |
{
|
|
154 |
/* Table */
|
|
155 |
push(getTableName()); |
|
156 |
||
157 |
/* Unique */
|
|
158 |
push(getIndex().is_unique()); |
|
159 |
||
160 |
/* Key_name */
|
|
161 |
push(getIndex().name()); |
|
162 |
||
163 |
/* Seq_in_index */
|
|
164 |
push(static_cast<int64_t>(index_part_iterator + 1)); |
|
165 |
||
166 |
/* Column_name */
|
|
167 |
push(getTableProto().field(getIndexPart().fieldnr()).name()); |
|
168 |
}
|