drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
table_cache.cc
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
23#include <plugin/table_cache_dictionary/dictionary.h>
24#include <drizzled/table.h>
25#include <drizzled/table/cache.h>
26#include <drizzled/pthread_globals.h>
27
28using namespace drizzled;
29using namespace std;
30
31table_cache_dictionary::TableCache::TableCache() :
32 plugin::TableFunction("DATA_DICTIONARY", "TABLE_CACHE")
33{
34 add_field("SESSION_ID", plugin::TableFunction::NUMBER, 0, false);
35 add_field("TABLE_SCHEMA", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
36 add_field("TABLE_NAME", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
37 add_field("VERSION", plugin::TableFunction::NUMBER, 0, false);
38 add_field("IS_NAME_LOCKED", plugin::TableFunction::BOOLEAN, 0, false);
39 add_field("ROWS", plugin::TableFunction::NUMBER, 0, false);
40 add_field("AVG_ROW_LENGTH", plugin::TableFunction::NUMBER, 0, false);
41 add_field("TABLE_SIZE", plugin::TableFunction::NUMBER, 0, false);
42 add_field("AUTO_INCREMENT", plugin::TableFunction::NUMBER, 0, false);
43}
44
45table_cache_dictionary::TableCache::Generator::Generator(drizzled::Field **arg) :
46 drizzled::plugin::TableFunction::Generator(arg),
47 is_primed(false),
48 scopedLock(table::Cache::mutex())
49{
50
51 for (table::CacheMap::const_iterator iter= table::getCache().begin();
52 iter != table::getCache().end();
53 iter++)
54 {
55 table_list.push_back(iter->second);
56 }
57 std::sort(table_list.begin(), table_list.end(), Table::compare);
58}
59
60bool table_cache_dictionary::TableCache::Generator::nextCore()
61{
62 if (is_primed)
63 {
64 table_list_iterator++;
65 }
66 else
67 {
68 is_primed= true;
69 table_list_iterator= table_list.begin();
70 }
71
72 if (table_list_iterator == table_list.end())
73 return false;
74
75 table= *table_list_iterator;
76
77 return true;
78}
79
80bool table_cache_dictionary::TableCache::Generator::next()
81{
82 while (not nextCore())
83 {
84 if (table_list_iterator != table_list.end())
85 continue;
86
87 return false;
88 }
89
90 return true;
91}
92
93bool table_cache_dictionary::TableCache::Generator::populate()
94{
95 if (not next())
96 return false;
97
98 fill();
99
100 return true;
101}
102
104{
109
110 /* SESSION_ID 1 */
111 if (table->getSession())
112 push(table->getSession()->getSessionId());
113 else
114 push(static_cast<int64_t>(0));
115
116 /* TABLE_SCHEMA 2 */
117 push(table->getShare()->getSchemaNameRef());
118
119 /* TABLE_NAME 3 */
120 push(table->getShare()->getTableNameRef());
121
122 /* VERSION 4 */
123 push(static_cast<int64_t>(table->getShare()->getVersion()));
124
125 /* IS_NAME_LOCKED 5 */
126 push(table->isNameLock());
127
128 /* ROWS 6 */
129 push(static_cast<uint64_t>(table->getCursor().records()));
130
131 /* AVG_ROW_LENGTH 7 */
132 push(table->getCursor().rowSize());
133
134 /* TABLE_SIZE 8 */
135 push(table->getCursor().tableSize());
136
137 /* AUTO_INCREMENT 9 */
138 push(table->getCursor().getNextInsertId());
139}
TODO: Rename this file - func.h is stupid.
STL namespace.