mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Merge pull request #16205 from azat/do-not-cache-dictGet
Do not cache dictionary for dictGet*/dictHas*
This commit is contained in:
commit
cb4945d8b0
@ -82,13 +82,13 @@ public:
|
||||
|
||||
std::shared_ptr<const IDictionaryBase> getDictionary(const String & dictionary_name)
|
||||
{
|
||||
auto dict = std::atomic_load(&dictionary);
|
||||
if (dict)
|
||||
return dict;
|
||||
String resolved_name = DatabaseCatalog::instance().resolveDictionaryName(dictionary_name);
|
||||
dict = external_loader.getDictionary(resolved_name);
|
||||
context.checkAccess(AccessType::dictGet, dict->getDatabaseOrNoDatabaseTag(), dict->getDictionaryID().getTableName());
|
||||
std::atomic_store(&dictionary, dict);
|
||||
auto dict = external_loader.getDictionary(resolved_name);
|
||||
if (!access_checked)
|
||||
{
|
||||
context.checkAccess(AccessType::dictGet, dict->getDatabaseOrNoDatabaseTag(), dict->getDictionaryID().getTableName());
|
||||
access_checked = true;
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
|
||||
@ -122,6 +122,8 @@ private:
|
||||
const Context & context;
|
||||
const ExternalDictionariesLoader & external_loader;
|
||||
mutable std::shared_ptr<const IDictionaryBase> dictionary;
|
||||
/// Access cannot be not granted, since in this case checkAccess() will throw and access_checked will not be updated.
|
||||
std::atomic<bool> access_checked = false;
|
||||
};
|
||||
|
||||
|
||||
|
@ -0,0 +1,4 @@
|
||||
1
|
||||
2
|
||||
2
|
||||
1
|
@ -0,0 +1,26 @@
|
||||
set allow_nondeterministic_optimize_skip_unused_shards=1;
|
||||
set optimize_skip_unused_shards=1;
|
||||
set force_optimize_skip_unused_shards=2;
|
||||
|
||||
drop database if exists db_01527_ranges;
|
||||
drop table if exists dist_01527;
|
||||
drop table if exists data_01527;
|
||||
|
||||
create database db_01527_ranges;
|
||||
|
||||
create table data_01527 engine=Memory() as select toUInt64(number) key from numbers(2);
|
||||
create table dist_01527 as data_01527 engine=Distributed('test_cluster_two_shards', currentDatabase(), data_01527, dictGetUInt64('db_01527_ranges.dict', 'shard', key));
|
||||
|
||||
create table db_01527_ranges.data engine=Memory() as select number key, number shard from numbers(100);
|
||||
create dictionary db_01527_ranges.dict (key UInt64, shard UInt64) primary key key source(clickhouse(host '127.0.0.1' port 9000 table 'data' db 'db_01527_ranges' user 'default' password '')) lifetime(0) layout(hashed());
|
||||
system reload dictionary db_01527_ranges.dict;
|
||||
|
||||
select _shard_num from dist_01527 where key=0;
|
||||
select _shard_num from dist_01527 where key=1;
|
||||
|
||||
drop table db_01527_ranges.data sync;
|
||||
create table db_01527_ranges.data engine=Memory() as select number key, number+1 shard from numbers(100);
|
||||
system reload dictionary db_01527_ranges.dict;
|
||||
|
||||
select _shard_num from dist_01527 where key=0;
|
||||
select _shard_num from dist_01527 where key=1;
|
Loading…
Reference in New Issue
Block a user