00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include <plugin/table_cache_dictionary/dictionary.h>
00024 #include <drizzled/table.h>
00025 #include <drizzled/table/cache.h>
00026 #include <drizzled/pthread_globals.h>
00027
00028 using namespace drizzled;
00029 using namespace std;
00030
00031 table_cache_dictionary::TableCache::TableCache() :
00032 plugin::TableFunction("DATA_DICTIONARY", "TABLE_CACHE")
00033 {
00034 add_field("SESSION_ID", plugin::TableFunction::NUMBER, 0, false);
00035 add_field("TABLE_SCHEMA", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
00036 add_field("TABLE_NAME", plugin::TableFunction::STRING, MAXIMUM_IDENTIFIER_LENGTH, false);
00037 add_field("VERSION", plugin::TableFunction::NUMBER, 0, false);
00038 add_field("IS_NAME_LOCKED", plugin::TableFunction::BOOLEAN, 0, false);
00039 add_field("ROWS", plugin::TableFunction::NUMBER, 0, false);
00040 add_field("AVG_ROW_LENGTH", plugin::TableFunction::NUMBER, 0, false);
00041 add_field("TABLE_SIZE", plugin::TableFunction::NUMBER, 0, false);
00042 add_field("AUTO_INCREMENT", plugin::TableFunction::NUMBER, 0, false);
00043 }
00044
00045 table_cache_dictionary::TableCache::Generator::Generator(drizzled::Field **arg) :
00046 drizzled::plugin::TableFunction::Generator(arg),
00047 is_primed(false),
00048 scopedLock(table::Cache::mutex())
00049 {
00050
00051 for (table::CacheMap::const_iterator iter= table::getCache().begin();
00052 iter != table::getCache().end();
00053 iter++)
00054 {
00055 table_list.push_back(iter->second);
00056 }
00057 std::sort(table_list.begin(), table_list.end(), Table::compare);
00058 }
00059
00060 bool table_cache_dictionary::TableCache::Generator::nextCore()
00061 {
00062 if (is_primed)
00063 {
00064 table_list_iterator++;
00065 }
00066 else
00067 {
00068 is_primed= true;
00069 table_list_iterator= table_list.begin();
00070 }
00071
00072 if (table_list_iterator == table_list.end())
00073 return false;
00074
00075 table= *table_list_iterator;
00076
00077 return true;
00078 }
00079
00080 bool table_cache_dictionary::TableCache::Generator::next()
00081 {
00082 while (not nextCore())
00083 {
00084 if (table_list_iterator != table_list.end())
00085 continue;
00086
00087 return false;
00088 }
00089
00090 return true;
00091 }
00092
00093 bool table_cache_dictionary::TableCache::Generator::populate()
00094 {
00095 if (not next())
00096 return false;
00097
00098 fill();
00099
00100 return true;
00101 }
00102
00103 void table_cache_dictionary::TableCache::Generator::fill()
00104 {
00110
00111 if (table->getSession())
00112 push(table->getSession()->getSessionId());
00113 else
00114 push(static_cast<int64_t>(0));
00115
00116
00117 push(table->getShare()->getSchemaNameRef());
00118
00119
00120 push(table->getShare()->getTableNameRef());
00121
00122
00123 push(static_cast<int64_t>(table->getShare()->getVersion()));
00124
00125
00126 push(table->isNameLock());
00127
00128
00129 push(static_cast<uint64_t>(table->getCursor().records()));
00130
00131
00132 push(table->getCursor().rowSize());
00133
00134
00135 push(table->getCursor().tableSize());
00136
00137
00138 push(table->getCursor().getNextInsertId());
00139 }