Skip to content

Commit 5e7439e

Browse files
committed
Add docs, move some code around
1 parent 80ec0ea commit 5e7439e

File tree

13 files changed

+106
-68
lines changed

13 files changed

+106
-68
lines changed

docs/en/operations/server-configuration-parameters/settings.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,34 @@ Type: `Double`
449449

450450
Default: `0.5`
451451

452+
## query_condition_cache_policy {#query_condition_cache_policy}
453+
454+
Query condition cache policy name.
455+
456+
Type: `String`
457+
458+
Default: `SLRU`
459+
460+
## query_condition_cache_size {#query_condition_cache_size}
461+
462+
Maximum size of the query condition cache.
463+
464+
:::note
465+
This setting can be modified at runtime and will take effect immediately.
466+
:::
467+
468+
Type: `UInt64`
469+
470+
Default: `1073741824` (100 MiB)
471+
472+
## query_condition_cache_size_ratio {#query_condition_cache_size_ratio}
473+
474+
The size of the protected queue (in case of SLRU policy) in the query condition cache relative to the cache's total size.
475+
476+
Type: `Double`
477+
478+
Default: `0.5`
479+
452480
## max_backup_bandwidth_for_server {#max_backup_bandwidth_for_server}
453481

454482
The maximum read speed in bytes per second for all backups on server. Zero means unlimited.

docs/en/sql-reference/statements/system.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ Its size can be configured using the server-level setting [`uncompressed_cache_s
136136
Clears the compiled expression cache.
137137
The compiled expression cache is enabled/disabled with the query/user/profile-level setting [`compile_expressions`](../../operations/settings/settings.md#compile_expressions).
138138

139+
## DROP QUERY CONDITION CACHE {#drop-query-condition-cache}
140+
141+
Clears the query condition cache.
142+
139143
## DROP QUERY CACHE {#drop-query-cache}
140144

141145
```sql

programs/local/LocalServer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -828,12 +828,12 @@ void LocalServer::processConfig()
828828
}
829829
global_context->setMMappedFileCache(mmap_cache_size);
830830

831-
/// Initialize a dummy query result cache.
832-
global_context->setQueryResultCache(0, 0, 0, 0);
833-
834831
/// Initialize a dummy query condition cache.
835832
global_context->setQueryConditionCache(DEFAULT_QUERY_CONDITION_CACHE_POLICY, 0, 0);
836833

834+
/// Initialize a dummy query result cache.
835+
global_context->setQueryResultCache(0, 0, 0, 0);
836+
837837
/// Initialize allowed tiers
838838
global_context->getAccessControl().setAllowTierSettings(server_settings[ServerSetting::allow_feature_tier]);
839839

programs/server/Server.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,16 @@ try
17221722
}
17231723
global_context->setMMappedFileCache(mmap_cache_size);
17241724

1725+
String query_condition_cache_policy = server_settings[ServerSetting::query_condition_cache_policy];
1726+
size_t query_condition_cache_size = server_settings[ServerSetting::query_condition_cache_size];
1727+
double query_condition_cache_size_ratio = server_settings[ServerSetting::query_condition_cache_size_ratio];
1728+
if (query_condition_cache_size > max_cache_size)
1729+
{
1730+
query_condition_cache_size = max_cache_size;
1731+
LOG_INFO(log, "Lowered query condition cache size to {} because the system has limited RAM", formatReadableSizeWithBinarySuffix(query_condition_cache_size));
1732+
}
1733+
global_context->setQueryConditionCache(query_condition_cache_policy, query_condition_cache_size, query_condition_cache_size_ratio);
1734+
17251735
size_t query_result_cache_max_size_in_bytes = config().getUInt64("query_cache.max_size_in_bytes", DEFAULT_QUERY_RESULT_CACHE_MAX_SIZE);
17261736
size_t query_result_cache_max_entries = config().getUInt64("query_cache.max_entries", DEFAULT_QUERY_RESULT_CACHE_MAX_ENTRIES);
17271737
size_t query_result_cache_max_entry_size_in_bytes = config().getUInt64("query_cache.max_entry_size_in_bytes", DEFAULT_QUERY_RESULT_CACHE_MAX_ENTRY_SIZE_IN_BYTES);
@@ -1733,16 +1743,6 @@ try
17331743
}
17341744
global_context->setQueryResultCache(query_result_cache_max_size_in_bytes, query_result_cache_max_entries, query_result_cache_max_entry_size_in_bytes, query_result_cache_max_entry_size_in_rows);
17351745

1736-
String query_condition_cache_policy = server_settings[ServerSetting::query_condition_cache_policy];
1737-
size_t query_condition_cache_size = server_settings[ServerSetting::query_condition_cache_size];
1738-
double query_condition_cache_size_ratio = server_settings[ServerSetting::query_condition_cache_size_ratio];
1739-
if (query_condition_cache_size > max_cache_size)
1740-
{
1741-
query_condition_cache_size = max_cache_size;
1742-
LOG_INFO(log, "Lowered query condition cache size to {} because the system has limited RAM", formatReadableSizeWithBinarySuffix(query_condition_cache_size));
1743-
}
1744-
global_context->setQueryConditionCache(query_condition_cache_policy, query_condition_cache_size, query_condition_cache_size_ratio);
1745-
17461746
#if USE_EMBEDDED_COMPILER
17471747
size_t compiled_expression_cache_max_size_in_bytes = server_settings[ServerSetting::compiled_expression_cache_size];
17481748
size_t compiled_expression_cache_max_elements = server_settings[ServerSetting::compiled_expression_cache_elements_size];

src/Access/Common/AccessType.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ enum class AccessType : uint8_t
172172
M(SYSTEM_DROP_UNCOMPRESSED_CACHE, "SYSTEM DROP UNCOMPRESSED, DROP UNCOMPRESSED CACHE, DROP UNCOMPRESSED", GLOBAL, SYSTEM_DROP_CACHE) \
173173
M(SYSTEM_DROP_SKIPPING_INDEX_CACHE, "SYSTEM DROP SKIPPING INDEX CACHE, DROP SKIPPING INDEX CACHE", GLOBAL, SYSTEM_DROP_CACHE) \
174174
M(SYSTEM_DROP_MMAP_CACHE, "SYSTEM DROP MMAP, DROP MMAP CACHE, DROP MMAP", GLOBAL, SYSTEM_DROP_CACHE) \
175-
M(SYSTEM_DROP_QUERY_CACHE, "SYSTEM DROP QUERY, DROP QUERY CACHE, DROP QUERY", GLOBAL, SYSTEM_DROP_CACHE) \
176175
M(SYSTEM_DROP_QUERY_CONDITION_CACHE, "SYSTEM DROP QUERY CONDITION, DROP QUERY CONDITION CACHE, DROP QUERY CONDITION", GLOBAL, SYSTEM_DROP_CACHE) \
176+
M(SYSTEM_DROP_QUERY_CACHE, "SYSTEM DROP QUERY, DROP QUERY CACHE, DROP QUERY", GLOBAL, SYSTEM_DROP_CACHE) \
177177
M(SYSTEM_DROP_COMPILED_EXPRESSION_CACHE, "SYSTEM DROP COMPILED EXPRESSION, DROP COMPILED EXPRESSION CACHE, DROP COMPILED EXPRESSIONS", GLOBAL, SYSTEM_DROP_CACHE) \
178178
M(SYSTEM_DROP_FILESYSTEM_CACHE, "SYSTEM DROP FILESYSTEM CACHE, DROP FILESYSTEM CACHE", GLOBAL, SYSTEM_DROP_CACHE) \
179179
M(SYSTEM_DROP_DISTRIBUTED_CACHE, "SYSTEM DROP DISTRIBUTED CACHE, DROP DISTRIBUTED CACHE", GLOBAL, SYSTEM_DROP_CACHE) \

src/Core/Defines.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ static constexpr auto DEFAULT_SKIPPING_INDEX_CACHE_MAX_ENTRIES = 10'000'000;
103103
static constexpr auto DEFAULT_MMAP_CACHE_MAX_SIZE = 1_KiB; /// chosen by rolling dice
104104
static constexpr auto DEFAULT_COMPILED_EXPRESSION_CACHE_MAX_SIZE = 128_MiB;
105105
static constexpr auto DEFAULT_COMPILED_EXPRESSION_CACHE_MAX_ENTRIES = 10'000;
106+
static constexpr auto DEFAULT_QUERY_CONDITION_CACHE_POLICY = "SLRU";
107+
static constexpr auto DEFAULT_QUERY_CONDITION_CACHE_MAX_SIZE = 100_MiB;
108+
static constexpr auto DEFAULT_QUERY_CONDITION_CACHE_SIZE_RATIO = 0.5l;
106109
static constexpr auto DEFAULT_QUERY_RESULT_CACHE_MAX_SIZE = 1_GiB;
107110
static constexpr auto DEFAULT_QUERY_RESULT_CACHE_MAX_ENTRIES = 1024uz;
108111
static constexpr auto DEFAULT_QUERY_RESULT_CACHE_MAX_ENTRY_SIZE_IN_BYTES = 1_MiB;
@@ -112,9 +115,6 @@ static constexpr auto DEFAULT_PAGE_CACHE_SIZE_RATIO = 0.5l;
112115
static constexpr auto DEFAULT_PAGE_CACHE_MIN_SIZE = 100_MiB;
113116
/// It's ok that max < min. Max takes precedence, i.e. max = 0 disables the cache even if min > 0.
114117
static constexpr auto DEFAULT_PAGE_CACHE_MAX_SIZE = 0_MiB;
115-
static constexpr auto DEFAULT_QUERY_CONDITION_CACHE_POLICY = "SLRU";
116-
static constexpr auto DEFAULT_QUERY_CONDITION_CACHE_MAX_SIZE = 100_MiB;
117-
static constexpr auto DEFAULT_QUERY_CONDITION_CACHE_SIZE_RATIO = 0.5l;
118118

119119
/// Query profiler cannot work with sanitizers.
120120
/// Sanitizers are using quick "frame walking" stack unwinding (this implies -fno-omit-frame-pointer)

src/Core/ServerSettings.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,12 @@ namespace DB
516516
\
517517
DECLARE(UInt64, compiled_expression_cache_elements_size, DEFAULT_COMPILED_EXPRESSION_CACHE_MAX_ENTRIES, R"(Sets the cache size (in elements) for [compiled expressions](../../operations/caches.md).)", 0) \
518518
DECLARE(String, query_condition_cache_policy, DEFAULT_QUERY_CONDITION_CACHE_POLICY, "Query condition cache policy name.", 0) \
519-
DECLARE(UInt64, query_condition_cache_size, DEFAULT_QUERY_CONDITION_CACHE_MAX_SIZE, "Size of the query condition cache.", 0) \
519+
DECLARE(UInt64, query_condition_cache_size, DEFAULT_QUERY_CONDITION_CACHE_MAX_SIZE, R"(
520+
Maximum size of the query condition cache.
521+
:::note
522+
This setting can be modified at runtime and will take effect immediately.
523+
:::
524+
)", 0) \
520525
DECLARE(Double, query_condition_cache_size_ratio, DEFAULT_QUERY_CONDITION_CACHE_SIZE_RATIO, "The size of the protected queue in the query condition cache relative to the cache's total size.", 0) \
521526
\
522527
DECLARE(Bool, disable_internal_dns_cache, false, "Disable internal DNS caching at all.", 0) \

src/Core/SettingsChangesHistory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const VersionToSettingsChangesMap & getSettingsChangesHistory()
6969
addSettingsChanges(settings_changes_history, "25.3",
7070
{
7171
{"use_page_cache_with_distributed_cache", false, false, "New setting"},
72+
{"use_query_condition_cache", false, false, "New setting."},
7273
});
7374
addSettingsChanges(settings_changes_history, "25.2",
7475
{
@@ -86,7 +87,6 @@ const VersionToSettingsChangesMap & getSettingsChangesHistory()
8687
{"output_format_parquet_bloom_filter_flush_threshold_bytes", 128 * 1024 * 1024, 128 * 1024 * 1024, "New setting."},
8788
{"output_format_pretty_max_rows", 10000, 1000, "It is better for usability - less amount to scroll."},
8889
{"restore_replicated_merge_tree_to_shared_merge_tree", false, false, "New setting."},
89-
{"use_query_condition_cache", false, false, "New setting."},
9090
{"parallel_replicas_only_with_analyzer", true, true, "Parallel replicas is supported only with analyzer enabled"},
9191
{"s3_allow_multipart_copy", true, true, "New setting."},
9292
/// Release closed. Please use 25.3

src/Interpreters/Context.cpp

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
#include <Interpreters/TemporaryDataOnDisk.h>
5757
#include <Interpreters/Cache/FileCacheFactory.h>
5858
#include <Interpreters/Cache/FileCache.h>
59-
#include <Interpreters/Cache/QueryResultCache.h>
6059
#include <Interpreters/Cache/QueryConditionCache.h>
60+
#include <Interpreters/Cache/QueryResultCache.h>
6161
#include <Interpreters/SessionTracker.h>
6262
#include <Core/ServerSettings.h>
6363
#include <Interpreters/PreparedSets.h>
@@ -442,10 +442,10 @@ struct ContextSharedPart : boost::noncopyable
442442
mutable std::unique_ptr<ThreadPool> build_vector_similarity_index_threadpool; /// Threadpool for vector-similarity index creation.
443443
mutable UncompressedCachePtr index_uncompressed_cache TSA_GUARDED_BY(mutex); /// The cache of decompressed blocks for MergeTree indices.
444444
mutable SkippingIndexCachePtr skipping_index_cache TSA_GUARDED_BY(mutex); /// Cache of deserialized secondary index granules.
445+
mutable QueryConditionCachePtr query_condition_cache TSA_GUARDED_BY(mutex); /// Cache of matching marks for predicates
445446
mutable QueryResultCachePtr query_result_cache TSA_GUARDED_BY(mutex); /// Cache of query results.
446447
mutable MarkCachePtr index_mark_cache TSA_GUARDED_BY(mutex); /// Cache of marks in compressed files of MergeTree indices.
447448
mutable MMappedFileCachePtr mmap_cache TSA_GUARDED_BY(mutex); /// Cache of mmapped files to avoid frequent open/map/unmap/close and to reuse from several threads.
448-
mutable QueryConditionCachePtr query_condition_cache TSA_GUARDED_BY(mutex); /// Mark filter for caching query conditions
449449
AsynchronousMetrics * asynchronous_metrics TSA_GUARDED_BY(mutex) = nullptr; /// Points to asynchronous metrics
450450
mutable PageCachePtr page_cache TSA_GUARDED_BY(mutex); /// Userspace page cache.
451451
ProcessList process_list; /// Executing queries at the moment.
@@ -3604,6 +3604,42 @@ void Context::clearMMappedFileCache() const
36043604
cache->clear();
36053605
}
36063606

3607+
void Context::setQueryConditionCache(const String & cache_policy, size_t max_size_in_bytes, double size_ratio)
3608+
{
3609+
std::lock_guard lock(shared->mutex);
3610+
3611+
if (shared->query_condition_cache)
3612+
throw Exception(ErrorCodes::LOGICAL_ERROR, "Mark filter cache has been already create.");
3613+
3614+
shared->query_condition_cache = std::make_shared<QueryConditionCache>(cache_policy, max_size_in_bytes, size_ratio);
3615+
}
3616+
3617+
QueryConditionCachePtr Context::getQueryConditionCache() const
3618+
{
3619+
SharedLockGuard lock(shared->mutex);
3620+
return shared->query_condition_cache;
3621+
}
3622+
3623+
void Context::updateQueryConditionCacheConfiguration(const Poco::Util::AbstractConfiguration & config)
3624+
{
3625+
std::lock_guard lock(shared->mutex);
3626+
3627+
if (!shared->query_condition_cache)
3628+
throw Exception(ErrorCodes::LOGICAL_ERROR, "Query condition cache was not created yet.");
3629+
3630+
size_t max_size_in_bytes = config.getUInt64("query_condition_cache_size", DEFAULT_QUERY_CONDITION_CACHE_MAX_SIZE);
3631+
shared->query_condition_cache->setMaxSizeInBytes(max_size_in_bytes);
3632+
}
3633+
3634+
void Context::clearQueryConditionCache() const
3635+
{
3636+
std::lock_guard lock(shared->mutex);
3637+
3638+
if (shared->query_condition_cache)
3639+
shared->query_condition_cache->clear();
3640+
}
3641+
3642+
36073643
void Context::setQueryResultCache(size_t max_size_in_bytes, size_t max_entries, size_t max_entry_size_in_bytes, size_t max_entry_size_in_rows)
36083644
{
36093645
std::lock_guard lock(shared->mutex);
@@ -3643,41 +3679,6 @@ void Context::clearQueryResultCache(const std::optional<String> & tag) const
36433679
cache->clear(tag);
36443680
}
36453681

3646-
void Context::setQueryConditionCache(const String & cache_policy, size_t max_size_in_bytes, double size_ratio)
3647-
{
3648-
std::lock_guard lock(shared->mutex);
3649-
3650-
if (shared->query_condition_cache)
3651-
throw Exception(ErrorCodes::LOGICAL_ERROR, "Mark filter cache has been already create.");
3652-
3653-
shared->query_condition_cache = std::make_shared<QueryConditionCache>(cache_policy, max_size_in_bytes, size_ratio);
3654-
}
3655-
3656-
QueryConditionCachePtr Context::getQueryConditionCache() const
3657-
{
3658-
SharedLockGuard lock(shared->mutex);
3659-
return shared->query_condition_cache;
3660-
}
3661-
3662-
void Context::updateQueryConditionCacheConfiguration(const Poco::Util::AbstractConfiguration & config)
3663-
{
3664-
std::lock_guard lock(shared->mutex);
3665-
3666-
if (!shared->query_condition_cache)
3667-
throw Exception(ErrorCodes::LOGICAL_ERROR, "Query condition cache was not created yet.");
3668-
3669-
size_t max_size_in_bytes = config.getUInt64("query_condition_cache_size", DEFAULT_QUERY_CONDITION_CACHE_MAX_SIZE);
3670-
shared->query_condition_cache->setMaxSizeInBytes(max_size_in_bytes);
3671-
}
3672-
3673-
void Context::clearQueryConditionCache() const
3674-
{
3675-
std::lock_guard lock(shared->mutex);
3676-
3677-
if (shared->query_condition_cache)
3678-
shared->query_condition_cache->clear();
3679-
}
3680-
36813682
void Context::clearCaches() const
36823683
{
36833684
std::lock_guard lock(shared->mutex);
@@ -3710,11 +3711,11 @@ void Context::clearCaches() const
37103711
throw Exception(ErrorCodes::LOGICAL_ERROR, "Mmapped file cache was not created yet.");
37113712
shared->mmap_cache->clear();
37123713

3713-
/// Intentionally not clearing the query result cache which is transactionally inconsistent by design.
3714-
37153714
if (!shared->query_condition_cache)
37163715
throw Exception(ErrorCodes::LOGICAL_ERROR, "Query condition cache was not created yet.");
37173716
shared->query_condition_cache->clear();
3717+
3718+
/// Intentionally not clearing the query result cache which is transactionally inconsistent by design.
37183719
}
37193720

37203721
void Context::setAsynchronousMetrics(AsynchronousMetrics * asynchronous_metrics_)

src/Interpreters/InterpreterSystemQuery.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -408,18 +408,18 @@ BlockIO InterpreterSystemQuery::execute()
408408
getContext()->checkAccess(AccessType::SYSTEM_DROP_MMAP_CACHE);
409409
system_context->clearMMappedFileCache();
410410
break;
411-
case Type::DROP_QUERY_CACHE:
412-
{
413-
getContext()->checkAccess(AccessType::SYSTEM_DROP_QUERY_CACHE);
414-
getContext()->clearQueryResultCache(query.query_result_cache_tag);
415-
break;
416-
}
417411
case Type::DROP_QUERY_CONDITION_CACHE:
418412
{
419413
getContext()->checkAccess(AccessType::SYSTEM_DROP_QUERY_CONDITION_CACHE);
420414
getContext()->clearQueryConditionCache();
421415
break;
422416
}
417+
case Type::DROP_QUERY_CACHE:
418+
{
419+
getContext()->checkAccess(AccessType::SYSTEM_DROP_QUERY_CACHE);
420+
getContext()->clearQueryResultCache(query.query_result_cache_tag);
421+
break;
422+
}
423423
case Type::DROP_COMPILED_EXPRESSION_CACHE:
424424
#if USE_EMBEDDED_COMPILER
425425
getContext()->checkAccess(AccessType::SYSTEM_DROP_COMPILED_EXPRESSION_CACHE);
@@ -1451,8 +1451,8 @@ AccessRightsElements InterpreterSystemQuery::getRequiredAccessForDDLOnCluster()
14511451
case Type::DROP_MARK_CACHE:
14521452
case Type::DROP_PRIMARY_INDEX_CACHE:
14531453
case Type::DROP_MMAP_CACHE:
1454-
case Type::DROP_QUERY_CACHE:
14551454
case Type::DROP_QUERY_CONDITION_CACHE:
1455+
case Type::DROP_QUERY_CACHE:
14561456
case Type::DROP_COMPILED_EXPRESSION_CACHE:
14571457
case Type::DROP_UNCOMPRESSED_CACHE:
14581458
case Type::DROP_INDEX_MARK_CACHE:

0 commit comments

Comments
 (0)