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>
28 using namespace drizzled;
31 table_cache_dictionary::TableCache::TableCache() :
32 plugin::TableFunction(
"DATA_DICTIONARY",
"TABLE_CACHE")
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);
45 table_cache_dictionary::TableCache::Generator::Generator(
drizzled::Field **arg) :
46 drizzled::plugin::TableFunction::Generator(arg),
48 scopedLock(table::Cache::mutex())
51 for (table::CacheMap::const_iterator iter= table::getCache().begin();
52 iter != table::getCache().end();
55 table_list.push_back(iter->second);
57 std::sort(table_list.begin(), table_list.end(), Table::compare);
60 bool table_cache_dictionary::TableCache::Generator::nextCore()
64 table_list_iterator++;
69 table_list_iterator= table_list.begin();
72 if (table_list_iterator == table_list.end())
75 table= *table_list_iterator;
80 bool table_cache_dictionary::TableCache::Generator::next()
82 while (not nextCore())
84 if (table_list_iterator != table_list.end())
93 bool table_cache_dictionary::TableCache::Generator::populate()
111 if (table->getSession())
112 push(table->getSession()->getSessionId());
114 push(static_cast<int64_t>(0));
117 push(table->getShare()->getSchemaNameRef());
120 push(table->getShare()->getTableNameRef());
123 push(static_cast<int64_t>(table->getShare()->getVersion()));
126 push(table->isNameLock());
129 push(static_cast<uint64_t>(table->getCursor().records()));
132 push(table->getCursor().rowSize());
135 push(table->getCursor().tableSize());
138 push(table->getCursor().getNextInsertId());