mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Try make cache for getSampleBlock (#2313)
* Cache for getSampleBlock * Update InterpreterSelectWithUnionQuery.cpp * Update 00632_get_sample_block_cache.sql * Add tests
This commit is contained in:
parent
ead9493741
commit
dc721ed721
@ -1732,6 +1732,11 @@ void Context::setFormatSchemaPath(const String & path)
|
||||
shared->format_schema_path = path;
|
||||
}
|
||||
|
||||
Context::getSampleBlockCacheType & Context::getSampleBlockCache() const
|
||||
{
|
||||
return getQueryContext().get_sample_block_cache;
|
||||
}
|
||||
|
||||
std::shared_ptr<ActionLocksManager> Context::getActionLocksManager()
|
||||
{
|
||||
auto lock = getLock();
|
||||
@ -1742,7 +1747,6 @@ std::shared_ptr<ActionLocksManager> Context::getActionLocksManager()
|
||||
return shared->action_locks_manager;
|
||||
}
|
||||
|
||||
|
||||
SessionCleaner::~SessionCleaner()
|
||||
{
|
||||
try
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <common/MultiVersion.h>
|
||||
#include <Core/Types.h>
|
||||
#include <Core/NamesAndTypes.h>
|
||||
#include <Core/Block.h>
|
||||
#include <Interpreters/Settings.h>
|
||||
#include <Interpreters/ClientInfo.h>
|
||||
#include <IO/CompressionSettings.h>
|
||||
@ -398,6 +399,10 @@ public:
|
||||
/// User name and session identifier. Named sessions are local to users.
|
||||
using SessionKey = std::pair<String, String>;
|
||||
|
||||
using getSampleBlockCacheType = std::unordered_map<std::string, Block>;
|
||||
mutable Context::getSampleBlockCacheType get_sample_block_cache;
|
||||
getSampleBlockCacheType & getSampleBlockCache() const;
|
||||
|
||||
private:
|
||||
/** Check if the current client has access to the specified database.
|
||||
* If access is denied, throw an exception.
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include <DataTypes/getLeastSupertype.h>
|
||||
#include <Columns/ColumnConst.h>
|
||||
#include <Common/typeid_cast.h>
|
||||
|
||||
#include <Parsers/queryToString.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
@ -157,7 +157,15 @@ Block InterpreterSelectWithUnionQuery::getSampleBlock(
|
||||
const ASTPtr & query_ptr,
|
||||
const Context & context)
|
||||
{
|
||||
return InterpreterSelectWithUnionQuery(query_ptr, context).getSampleBlock();
|
||||
auto & cache = context.getSampleBlockCache();
|
||||
/// Using query string because query_ptr changes for every internal SELECT
|
||||
auto key = queryToString(query_ptr);
|
||||
if (cache.find(key) != cache.end())
|
||||
{
|
||||
return cache[key];
|
||||
}
|
||||
|
||||
return cache[key] = InterpreterSelectWithUnionQuery(query_ptr, context).getSampleBlock();
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,2 @@
|
||||
Still alive
|
||||
65535
|
174
dbms/tests/queries/0_stateless/00632_get_sample_block_cache.sql
Normal file
174
dbms/tests/queries/0_stateless/00632_get_sample_block_cache.sql
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user