diff --git a/src/Interpreters/InterpreterSelectQuery.cpp b/src/Interpreters/InterpreterSelectQuery.cpp index a70c5667a36b..dc5c319fbd11 100644 --- a/src/Interpreters/InterpreterSelectQuery.cpp +++ b/src/Interpreters/InterpreterSelectQuery.cpp @@ -3200,8 +3200,16 @@ void InterpreterSelectQuery::initSettings() { auto & query = getSelectQuery(); if (query.settings()) + { InterpreterSetQuery(query.settings(), context).executeForCurrentContext(options.ignore_setting_constraints); + /// The old interpreter disabled the analyzer in IInterpreterUnionOrSelectQuery, but a SELECT + /// stored in a VIEW may enable it again here. Storages must not use analyzer-only query tree + /// paths (for example, StorageDistributed::read) when this interpreter built the query. + if (context->getSettingsRef().allow_experimental_analyzer) + context->setSetting("allow_experimental_analyzer", false); + } + const auto & client_info = context->getClientInfo(); auto min_major = DBMS_MIN_MAJOR_VERSION_WITH_CURRENT_AGGREGATION_VARIANT_SELECTION_METHOD; auto min_minor = DBMS_MIN_MINOR_VERSION_WITH_CURRENT_AGGREGATION_VARIANT_SELECTION_METHOD; diff --git a/tests/queries/0_stateless/04839_view_analyzer_setting_over_distributed.reference b/tests/queries/0_stateless/04839_view_analyzer_setting_over_distributed.reference new file mode 100644 index 000000000000..071137aa6b5d --- /dev/null +++ b/tests/queries/0_stateless/04839_view_analyzer_setting_over_distributed.reference @@ -0,0 +1,16 @@ +view analyzer 1, read analyzer 0 +2 +s1 2.5 +s2 7 +view analyzer 1, read analyzer 0, remote shard +s1 2.5 +s2 7 +view analyzer 1, read analyzer 1 +s1 2.5 +s2 7 +view analyzer 0, read analyzer 1 +s1 2.5 +s2 7 +view analyzer 0, read analyzer 0 +s1 2.5 +s2 7 diff --git a/tests/queries/0_stateless/04839_view_analyzer_setting_over_distributed.sql b/tests/queries/0_stateless/04839_view_analyzer_setting_over_distributed.sql new file mode 100644 index 000000000000..6d2c21ba1915 --- /dev/null +++ b/tests/queries/0_stateless/04839_view_analyzer_setting_over_distributed.sql @@ -0,0 +1,49 @@ +-- Tags: distributed + +-- The old interpreter must not use the analyzer-only Distributed path when a view's +-- stored SELECT has SETTINGS enable_analyzer = 1. + +DROP VIEW IF EXISTS v_new_04839; +DROP VIEW IF EXISTS v_old_04839; +DROP TABLE IF EXISTS dist_04839; +DROP TABLE IF EXISTS src_04839; + +CREATE TABLE src_04839 (trade_date Date, strategy String, pnl Float64, ts DateTime) ENGINE = Memory; +INSERT INTO src_04839 VALUES + ('2026-09-17', 's1', 1.5, '2026-09-17 10:00:00'), + ('2026-09-17', 's1', 2.5, '2026-09-17 11:00:00'), + ('2026-09-17', 's2', 7, '2026-09-17 09:00:00'), + ('2026-09-16', 's3', 9, '2026-09-16 10:00:00'); + +CREATE TABLE dist_04839 AS src_04839 ENGINE = Distributed(test_shard_localhost, currentDatabase(), src_04839); + +CREATE VIEW v_new_04839 AS + SELECT strategy, argMax(pnl, ts) AS pnl + FROM dist_04839 WHERE trade_date = '2026-09-17' + GROUP BY strategy SETTINGS enable_analyzer = 1; + +CREATE VIEW v_old_04839 AS + SELECT strategy, argMax(pnl, ts) AS pnl + FROM dist_04839 WHERE trade_date = '2026-09-17' + GROUP BY strategy SETTINGS enable_analyzer = 0; + +SELECT 'view analyzer 1, read analyzer 0'; +SELECT count() FROM v_new_04839 SETTINGS enable_analyzer = 0; +SELECT strategy, pnl FROM v_new_04839 ORDER BY strategy SETTINGS enable_analyzer = 0; + +SELECT 'view analyzer 1, read analyzer 0, remote shard'; +SELECT strategy, pnl FROM v_new_04839 ORDER BY strategy SETTINGS enable_analyzer = 0, prefer_localhost_replica = 0; + +SELECT 'view analyzer 1, read analyzer 1'; +SELECT strategy, pnl FROM v_new_04839 ORDER BY strategy SETTINGS enable_analyzer = 1; + +SELECT 'view analyzer 0, read analyzer 1'; +SELECT strategy, pnl FROM v_old_04839 ORDER BY strategy SETTINGS enable_analyzer = 1; + +SELECT 'view analyzer 0, read analyzer 0'; +SELECT strategy, pnl FROM v_old_04839 ORDER BY strategy SETTINGS enable_analyzer = 0; + +DROP VIEW v_new_04839; +DROP VIEW v_old_04839; +DROP TABLE dist_04839; +DROP TABLE src_04839;