ClickHouse/tests/queries/1_stateful/00041_aggregating_materialized_view.sql

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
1.5 KiB
MySQL
Raw Normal View History

DROP TABLE IF EXISTS test.basic;
DROP TABLE IF EXISTS test.visits_null;
CREATE TABLE test.visits_null
(
CounterID UInt32,
StartDate Date,
Sign Int8,
UserID UInt64
) ENGINE = Null;
2022-06-23 08:37:52 +00:00
set allow_deprecated_syntax_for_merge_tree=1;
CREATE MATERIALIZED VIEW test.basic
ENGINE = AggregatingMergeTree(StartDate, (CounterID, StartDate), 8192)
AS SELECT
CounterID,
StartDate,
2020-01-28 19:39:52 +00:00
sumState(Sign) AS Visits,
uniqState(UserID) AS Users
FROM test.visits_null
GROUP BY CounterID, StartDate;
INSERT INTO test.visits_null
SELECT
CounterID,
StartDate,
Sign,
UserID
FROM test.visits;
SELECT
StartDate,
2020-01-28 19:39:52 +00:00
sumMerge(Visits) AS Visits,
uniqMerge(Users) AS Users
FROM test.basic
GROUP BY StartDate
ORDER BY StartDate;
SELECT
StartDate,
2020-01-28 19:39:52 +00:00
sumMerge(Visits) AS Visits,
uniqMerge(Users) AS Users
FROM test.basic
WHERE CounterID = 942285
GROUP BY StartDate
ORDER BY StartDate;
SELECT
StartDate,
2020-03-17 23:51:35 +00:00
sum(Sign) AS Visits,
2020-01-28 19:39:52 +00:00
uniq(UserID) AS Users
FROM test.visits
WHERE CounterID = 942285
GROUP BY StartDate
ORDER BY StartDate;
OPTIMIZE TABLE test.basic;
OPTIMIZE TABLE test.basic;
OPTIMIZE TABLE test.basic;
OPTIMIZE TABLE test.basic;
OPTIMIZE TABLE test.basic;
OPTIMIZE TABLE test.basic;
OPTIMIZE TABLE test.basic;
OPTIMIZE TABLE test.basic;
OPTIMIZE TABLE test.basic;
OPTIMIZE TABLE test.basic;
DROP TABLE test.visits_null;
DROP TABLE test.basic;