From d79671ff8ca4d511d4df4531edec9eb16d5277eb Mon Sep 17 00:00:00 2001 From: Artur Pata Date: Thu, 30 Jul 2026 21:44:28 +0300 Subject: [PATCH 1/2] Add workaround for CH query condition cache bug --- config/runtime.exs | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index 91f056353d27..c78ed517e9b3 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -647,23 +647,36 @@ ch_transport_opts = ch_transport_opts end +# Workaround for a ClickHouse bug where sampled queries poison the query +# condition cache, causing subsequent unsampled queries to return invalid +# results. Sampling is EE only, so this is scoped to EE builds. +# Fixed upstream in ClickHouse/ClickHouse#108488; remove once ClickHouse +# updated. +ch_query_condition_cache_settings = + if config_env() in [:ce, :ce_dev, :ce_test] do + [] + else + [use_query_condition_cache: 0] + end + config :plausible, Plausible.ClickhouseRepo, queue_target: 500, queue_interval: 2000, timeout: 15_000, url: ch_db_url, transport_opts: ch_transport_opts, - settings: [ - readonly: 1, - join_algorithm: "direct,parallel_hash,hash", - # stops queries when :timeout ClickhouseRepo connection :timeout value reached - cancel_http_readonly_queries_on_client_close: 1, - # stops queries when they will likely take over 20s - # NB! when :timeout is overridden to be over 20s, - # for it to have meaningful effect, - # this must be overridden as well - max_execution_time: 20 - ] + settings: + [ + readonly: 1, + join_algorithm: "direct,parallel_hash,hash", + # stops queries when ClickhouseRepo connection :timeout value reached + cancel_http_readonly_queries_on_client_close: 1, + # stops queries when they will likely take over 20s + # NB! when :timeout is overridden to be over 20s, + # for it to have meaningful effect, + # this must be overridden as well + max_execution_time: 20 + ] ++ ch_query_condition_cache_settings config :plausible, Plausible.IngestRepo, queue_target: 500, From 70f9f3300877cad7d6fce539eb85cb6858cb94dd Mon Sep 17 00:00:00 2001 From: Artur Pata Date: Thu, 30 Jul 2026 21:45:04 +0300 Subject: [PATCH 2/2] Revert "Add workaround for CH query condition cache bug" This reverts commit d79671ff8ca4d511d4df4531edec9eb16d5277eb. --- config/runtime.exs | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index c78ed517e9b3..91f056353d27 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -647,36 +647,23 @@ ch_transport_opts = ch_transport_opts end -# Workaround for a ClickHouse bug where sampled queries poison the query -# condition cache, causing subsequent unsampled queries to return invalid -# results. Sampling is EE only, so this is scoped to EE builds. -# Fixed upstream in ClickHouse/ClickHouse#108488; remove once ClickHouse -# updated. -ch_query_condition_cache_settings = - if config_env() in [:ce, :ce_dev, :ce_test] do - [] - else - [use_query_condition_cache: 0] - end - config :plausible, Plausible.ClickhouseRepo, queue_target: 500, queue_interval: 2000, timeout: 15_000, url: ch_db_url, transport_opts: ch_transport_opts, - settings: - [ - readonly: 1, - join_algorithm: "direct,parallel_hash,hash", - # stops queries when ClickhouseRepo connection :timeout value reached - cancel_http_readonly_queries_on_client_close: 1, - # stops queries when they will likely take over 20s - # NB! when :timeout is overridden to be over 20s, - # for it to have meaningful effect, - # this must be overridden as well - max_execution_time: 20 - ] ++ ch_query_condition_cache_settings + settings: [ + readonly: 1, + join_algorithm: "direct,parallel_hash,hash", + # stops queries when :timeout ClickhouseRepo connection :timeout value reached + cancel_http_readonly_queries_on_client_close: 1, + # stops queries when they will likely take over 20s + # NB! when :timeout is overridden to be over 20s, + # for it to have meaningful effect, + # this must be overridden as well + max_execution_time: 20 + ] config :plausible, Plausible.IngestRepo, queue_target: 500,