|
56 | 56 | #include <Interpreters/TemporaryDataOnDisk.h> |
57 | 57 | #include <Interpreters/Cache/FileCacheFactory.h> |
58 | 58 | #include <Interpreters/Cache/FileCache.h> |
59 | | -#include <Interpreters/Cache/QueryResultCache.h> |
60 | 59 | #include <Interpreters/Cache/QueryConditionCache.h> |
| 60 | +#include <Interpreters/Cache/QueryResultCache.h> |
61 | 61 | #include <Interpreters/SessionTracker.h> |
62 | 62 | #include <Core/ServerSettings.h> |
63 | 63 | #include <Interpreters/PreparedSets.h> |
@@ -442,10 +442,10 @@ struct ContextSharedPart : boost::noncopyable |
442 | 442 | mutable std::unique_ptr<ThreadPool> build_vector_similarity_index_threadpool; /// Threadpool for vector-similarity index creation. |
443 | 443 | mutable UncompressedCachePtr index_uncompressed_cache TSA_GUARDED_BY(mutex); /// The cache of decompressed blocks for MergeTree indices. |
444 | 444 | 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 |
445 | 446 | mutable QueryResultCachePtr query_result_cache TSA_GUARDED_BY(mutex); /// Cache of query results. |
446 | 447 | mutable MarkCachePtr index_mark_cache TSA_GUARDED_BY(mutex); /// Cache of marks in compressed files of MergeTree indices. |
447 | 448 | 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 |
449 | 449 | AsynchronousMetrics * asynchronous_metrics TSA_GUARDED_BY(mutex) = nullptr; /// Points to asynchronous metrics |
450 | 450 | mutable PageCachePtr page_cache TSA_GUARDED_BY(mutex); /// Userspace page cache. |
451 | 451 | ProcessList process_list; /// Executing queries at the moment. |
@@ -3604,6 +3604,42 @@ void Context::clearMMappedFileCache() const |
3604 | 3604 | cache->clear(); |
3605 | 3605 | } |
3606 | 3606 |
|
| 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 | + |
3607 | 3643 | 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) |
3608 | 3644 | { |
3609 | 3645 | std::lock_guard lock(shared->mutex); |
@@ -3643,41 +3679,6 @@ void Context::clearQueryResultCache(const std::optional<String> & tag) const |
3643 | 3679 | cache->clear(tag); |
3644 | 3680 | } |
3645 | 3681 |
|
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 | | - |
3681 | 3682 | void Context::clearCaches() const |
3682 | 3683 | { |
3683 | 3684 | std::lock_guard lock(shared->mutex); |
@@ -3710,11 +3711,11 @@ void Context::clearCaches() const |
3710 | 3711 | throw Exception(ErrorCodes::LOGICAL_ERROR, "Mmapped file cache was not created yet."); |
3711 | 3712 | shared->mmap_cache->clear(); |
3712 | 3713 |
|
3713 | | - /// Intentionally not clearing the query result cache which is transactionally inconsistent by design. |
3714 | | - |
3715 | 3714 | if (!shared->query_condition_cache) |
3716 | 3715 | throw Exception(ErrorCodes::LOGICAL_ERROR, "Query condition cache was not created yet."); |
3717 | 3716 | shared->query_condition_cache->clear(); |
| 3717 | + |
| 3718 | + /// Intentionally not clearing the query result cache which is transactionally inconsistent by design. |
3718 | 3719 | } |
3719 | 3720 |
|
3720 | 3721 | void Context::setAsynchronousMetrics(AsynchronousMetrics * asynchronous_metrics_) |
|
0 commit comments