mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-15 10:52:30 +00:00
50 lines
1.6 KiB
C++
50 lines
1.6 KiB
C++
|
#include "StorageSystemQueryResultCache.h"
|
||
|
#include <DataTypes/DataTypeString.h>
|
||
|
#include <DataTypes/DataTypeDateTime.h>
|
||
|
#include <DataTypes/DataTypesNumber.h>
|
||
|
#include <Interpreters/Cache/QueryResultCache.h>
|
||
|
#include <Interpreters/Context.h>
|
||
|
|
||
|
|
||
|
namespace DB
|
||
|
{
|
||
|
|
||
|
NamesAndTypesList StorageSystemQueryResultCache::getNamesAndTypes()
|
||
|
{
|
||
|
return {
|
||
|
{"query", std::make_shared<DataTypeString>()},
|
||
|
{"query_hash", std::make_shared<DataTypeUInt64>()},
|
||
|
{"expires_at", std::make_shared<DataTypeDateTime>()},
|
||
|
{"stale", std::make_shared<DataTypeUInt8>()},
|
||
|
{"partition_key", std::make_shared<DataTypeString>()},
|
||
|
{"result_size", std::make_shared<DataTypeUInt64>()}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
StorageSystemQueryResultCache::StorageSystemQueryResultCache(const StorageID & table_id_)
|
||
|
: IStorageSystemOneBlock(table_id_)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void StorageSystemQueryResultCache::fillData(MutableColumns & res_columns, ContextPtr context, const SelectQueryInfo &) const
|
||
|
{
|
||
|
auto query_result_cache = context->getQueryResultCache();
|
||
|
|
||
|
if (!query_result_cache)
|
||
|
return;
|
||
|
|
||
|
std::lock_guard lock(query_result_cache->mutex);
|
||
|
|
||
|
for (const auto & [key, entry] : query_result_cache->cache)
|
||
|
{
|
||
|
res_columns[0]->insert(key.queryStringFromAst()); /// approximates the original query string
|
||
|
res_columns[1]->insert(key.ast->getTreeHash().first);
|
||
|
res_columns[2]->insert(std::chrono::system_clock::to_time_t(key.expires_at));
|
||
|
res_columns[3]->insert(key.expires_at < std::chrono::system_clock::now());
|
||
|
res_columns[4]->insert(key.partition_key);
|
||
|
res_columns[5]->insert(entry->allocatedBytes());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|