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/pthread_globals.h>
00026
00027 using namespace drizzled;
00028 using namespace std;
00029
00030 table_cache_dictionary::TableCache::TableCache() :
00031 plugin::TableFunction("DATA_DICTIONARY", "TABLE_CACHE")
00032 {
00033 add_field("SESSION_ID", plugin::TableFunction::NUMBER, 0, false);
00034 add_field("TABLE_SCHEMA");
00035 add_field("TABLE_NAME");
00036 add_field("VERSION", plugin::TableFunction::NUMBER, 0, false);
00037 add_field("IS_NAME_LOCKED", plugin::TableFunction::BOOLEAN, 0, false);
00038 add_field("ROWS", plugin::TableFunction::NUMBER, 0, false);
00039 add_field("AVG_ROW_LENGTH", plugin::TableFunction::NUMBER, 0, false);
00040 add_field("TABLE_SIZE", plugin::TableFunction::NUMBER, 0, false);
00041 add_field("AUTO_INCREMENT", plugin::TableFunction::NUMBER, 0, false);
00042 }
00043
00044 table_cache_dictionary::TableCache::Generator::Generator(drizzled::Field **arg) :
00045 drizzled::plugin::TableFunction::Generator(arg),
00046 is_primed(false),
00047 scopedLock(table::Cache::singleton().mutex())
00048 {
00049
00050 for (table::CacheMap::const_iterator iter= table::getCache().begin();
00051 iter != table::getCache().end();
00052 iter++)
00053 {
00054 table_list.push_back(iter->second);
00055 }
00056 std::sort(table_list.begin(), table_list.end(), Table::compare);
00057 }
00058
00059 table_cache_dictionary::TableCache::Generator::~Generator()
00060 {
00061 }
00062
00063 bool table_cache_dictionary::TableCache::Generator::nextCore()
00064 {
00065 if (is_primed)
00066 {
00067 table_list_iterator++;
00068 }
00069 else
00070 {
00071 is_primed= true;
00072 table_list_iterator= table_list.begin();
00073 }
00074
00075 if (table_list_iterator == table_list.end())
00076 return false;
00077
00078 table= *table_list_iterator;
00079
00080 return true;
00081 }
00082
00083 bool table_cache_dictionary::TableCache::Generator::next()
00084 {
00085 while (not nextCore())
00086 {
00087 if (table_list_iterator != table_list.end())
00088 continue;
00089
00090 return false;
00091 }
00092
00093 return true;
00094 }
00095
00096 bool table_cache_dictionary::TableCache::Generator::populate()
00097 {
00098 if (not next())
00099 return false;
00100
00101 fill();
00102
00103 return true;
00104 }
00105
00106 void table_cache_dictionary::TableCache::Generator::fill()
00107 {
00113
00114 if (table->getSession())
00115 push(table->getSession()->getSessionId());
00116 else
00117 push(static_cast<int64_t>(0));
00118
00119
00120 string arg;
00121 push(table->getShare()->getSchemaName(arg));
00122
00123
00124 push(table->getShare()->getTableName(arg));
00125
00126
00127 push(static_cast<int64_t>(table->getShare()->getVersion()));
00128
00129
00130 push(table->isNameLock());
00131
00132
00133 push(static_cast<uint64_t>(table->getCursor().records()));
00134
00135
00136 push(table->getCursor().rowSize());
00137
00138
00139 push(table->getCursor().tableSize());
00140
00141
00142 push(table->getCursor().getNextInsertId());
00143 }