2020-06-20 11:29:01 +00:00
|
|
|
SET send_logs_level = 'fatal';
|
2018-12-21 02:40:15 +00:00
|
|
|
|
2019-06-03 17:36:27 +00:00
|
|
|
DROP TABLE IF EXISTS test_00808;
|
|
|
|
CREATE TABLE test_00808(date Date, id Int8, name String, value Int64, sign Int8) ENGINE = CollapsingMergeTree(sign) ORDER BY (id, date);
|
2018-12-21 02:40:15 +00:00
|
|
|
|
2019-06-03 17:36:27 +00:00
|
|
|
INSERT INTO test_00808 VALUES('2000-01-01', 1, 'test string 1', 1, 1);
|
|
|
|
INSERT INTO test_00808 VALUES('2000-01-01', 2, 'test string 2', 2, 1);
|
2018-12-21 02:40:15 +00:00
|
|
|
|
|
|
|
SET enable_optimize_predicate_expression = 1;
|
|
|
|
|
2019-01-30 04:37:24 +00:00
|
|
|
SELECT '-------ENABLE OPTIMIZE PREDICATE-------';
|
2019-06-03 17:36:27 +00:00
|
|
|
SELECT * FROM (SELECT * FROM test_00808 FINAL) WHERE id = 1;
|
2020-03-02 12:24:10 +00:00
|
|
|
SELECT * FROM (SELECT * FROM test_00808 ORDER BY id LIMIT 1) WHERE id = 1;
|
2019-06-03 17:36:27 +00:00
|
|
|
SELECT * FROM (SELECT id FROM test_00808 GROUP BY id LIMIT 1 BY id) WHERE id = 1;
|
2019-01-30 04:37:24 +00:00
|
|
|
|
|
|
|
SET force_primary_key = 1;
|
|
|
|
|
|
|
|
SELECT '-------FORCE PRIMARY KEY-------';
|
2019-06-03 17:36:27 +00:00
|
|
|
SELECT * FROM (SELECT * FROM test_00808 LIMIT 1) WHERE id = 1; -- { serverError 277 }
|
|
|
|
SELECT * FROM (SELECT id FROM test_00808 GROUP BY id LIMIT 1 BY id) WHERE id = 1; -- { serverError 277 }
|
2019-01-30 04:37:24 +00:00
|
|
|
|
|
|
|
SELECT '-------CHECK STATEFUL FUNCTIONS-------';
|
2018-12-21 02:40:15 +00:00
|
|
|
SELECT n, z, changed FROM (
|
|
|
|
SELECT n, z, runningDifferenceStartingWithFirstValue(n) AS changed FROM (
|
|
|
|
SELECT ts, n,z FROM system.one ARRAY JOIN [1,3,4,5,6] AS ts,
|
|
|
|
[1,2,2,2,1] AS n, ['a', 'a', 'b', 'a', 'b'] AS z
|
|
|
|
ORDER BY n, ts DESC
|
|
|
|
)
|
|
|
|
) WHERE changed = 0;
|
|
|
|
|
2019-02-15 08:03:18 +00:00
|
|
|
|
|
|
|
SELECT arrayJoin(arrayMap(x -> x, arraySort(groupArray((ts, n))))) AS k FROM (
|
|
|
|
SELECT ts, n, z FROM system.one ARRAY JOIN [1, 3, 4, 5, 6] AS ts, [1, 2, 2, 2, 1] AS n, ['a', 'a', 'b', 'a', 'b'] AS z
|
|
|
|
ORDER BY n ASC, ts DESC
|
|
|
|
) WHERE z = 'a' GROUP BY z;
|
|
|
|
|
|
|
|
|
2019-06-03 17:36:27 +00:00
|
|
|
DROP TABLE IF EXISTS test_00808;
|
2020-09-17 13:59:14 +00:00
|
|
|
|
|
|
|
SELECT '-------finalizeAggregation should not be stateful (issue #14847)-------';
|
|
|
|
|
|
|
|
DROP TABLE IF EXISTS test_00808_push_down_with_finalizeAggregation;
|
|
|
|
|
|
|
|
CREATE TABLE test_00808_push_down_with_finalizeAggregation ENGINE = AggregatingMergeTree
|
|
|
|
ORDER BY n AS
|
|
|
|
SELECT
|
|
|
|
intDiv(number, 25) AS n,
|
|
|
|
avgState(number) AS s
|
|
|
|
FROM numbers(2500)
|
|
|
|
GROUP BY n;
|
|
|
|
|
2020-11-02 12:47:12 +00:00
|
|
|
SET force_primary_key = 1, enable_optimize_predicate_expression = 1;
|
2020-09-17 13:59:14 +00:00
|
|
|
|
|
|
|
SELECT *
|
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
n,
|
|
|
|
finalizeAggregation(s)
|
|
|
|
FROM test_00808_push_down_with_finalizeAggregation
|
|
|
|
)
|
|
|
|
WHERE (n >= 2) AND (n <= 5);
|
|
|
|
|
2020-11-02 12:47:12 +00:00
|
|
|
EXPLAIN SYNTAX SELECT *
|
2020-09-17 13:59:14 +00:00
|
|
|
FROM
|
|
|
|
(
|
|
|
|
SELECT
|
|
|
|
n,
|
|
|
|
finalizeAggregation(s)
|
|
|
|
FROM test_00808_push_down_with_finalizeAggregation
|
|
|
|
)
|
|
|
|
WHERE (n >= 2) AND (n <= 5);
|
|
|
|
|
|
|
|
DROP TABLE IF EXISTS test_00808_push_down_with_finalizeAggregation;
|