Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Interpreters/InterpreterSelectQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ namespace Setting
extern const SettingsMap additional_table_filters;
extern const SettingsUInt64 aggregation_in_order_max_block_bytes;
extern const SettingsUInt64 aggregation_memory_efficient_merge_threads;
extern const SettingsBool allow_experimental_analyzer;
extern const SettingsUInt64 allow_experimental_parallel_reading_from_replicas;
extern const SettingsBool allow_experimental_query_deduplication;
extern const SettingsBool async_socket_for_remote;
Expand Down Expand Up @@ -3351,8 +3352,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()[Setting::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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
DROP VIEW IF EXISTS v_old;
DROP TABLE IF EXISTS dist;
DROP TABLE IF EXISTS src;

CREATE TABLE src (trade_date Date, strategy String, pnl Float64, ts DateTime) ENGINE = Memory;
INSERT INTO src 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 AS src ENGINE = Distributed(test_shard_localhost, currentDatabase(), src);

CREATE VIEW v_new AS
SELECT strategy, argMax(pnl, ts) AS pnl
FROM dist WHERE trade_date = '2026-09-17'
GROUP BY strategy SETTINGS enable_analyzer = 1;

CREATE VIEW v_old AS
SELECT strategy, argMax(pnl, ts) AS pnl
FROM dist 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 SETTINGS enable_analyzer = 0;
SELECT strategy, pnl FROM v_new ORDER BY strategy SETTINGS enable_analyzer = 0;

SELECT 'view analyzer 1, read analyzer 0, remote shard';
SELECT strategy, pnl FROM v_new ORDER BY strategy SETTINGS enable_analyzer = 0, prefer_localhost_replica = 0;

SELECT 'view analyzer 1, read analyzer 1';
SELECT strategy, pnl FROM v_new ORDER BY strategy SETTINGS enable_analyzer = 1;

SELECT 'view analyzer 0, read analyzer 1';
SELECT strategy, pnl FROM v_old ORDER BY strategy SETTINGS enable_analyzer = 1;

SELECT 'view analyzer 0, read analyzer 0';
SELECT strategy, pnl FROM v_old ORDER BY strategy SETTINGS enable_analyzer = 0;

DROP VIEW v_new;
DROP VIEW v_old;
DROP TABLE dist;
DROP TABLE src;
Loading