ClickHouse/tests/queries/1_stateful/00172_hits_joins.sql.j2

221 lines
4.5 KiB
Plaintext
Raw Normal View History

2023-02-03 13:34:18 +00:00
-- Tags: no-parallel-replicas
2023-01-16 12:33:45 +00:00
{% for join_algorithm in ['hash', 'parallel_hash', 'full_sorting_merge', 'grace_hash'] -%}
2022-05-20 12:00:37 +00:00
2023-01-16 12:33:45 +00:00
SET max_rows_in_join = '{% if join_algorithm == 'grace_hash' %}10K{% else %}0{% endif %}';
SET grace_hash_join_initial_buckets = 4;
2022-09-15 12:14:27 +00:00
2022-05-20 12:00:37 +00:00
SELECT '--- {{ join_algorithm }} ---';
SET join_algorithm = '{{ join_algorithm }}';
SELECT
EventDate,
hits,
visits
FROM
(
SELECT
EventDate,
count() AS hits
FROM test.hits
GROUP BY EventDate
) ANY LEFT JOIN
(
SELECT
StartDate AS EventDate,
sum(Sign) AS visits
FROM test.visits
GROUP BY EventDate
) USING EventDate
ORDER BY hits DESC
LIMIT 10
SETTINGS joined_subquery_requires_alias = 0;
SELECT
EventDate,
count() AS hits,
any(visits)
FROM test.hits ANY LEFT JOIN
(
SELECT
StartDate AS EventDate,
sum(Sign) AS visits
FROM test.visits
GROUP BY EventDate
) USING EventDate
GROUP BY EventDate
ORDER BY hits DESC
LIMIT 10
2022-04-20 11:47:16 +00:00
SETTINGS joined_subquery_requires_alias = 0;
SELECT
domain,
hits,
visits
FROM
(
SELECT
domain(URL) AS domain,
count() AS hits
FROM test.hits
GROUP BY domain
) ANY LEFT JOIN
(
SELECT
domain(StartURL) AS domain,
sum(Sign) AS visits
FROM test.visits
GROUP BY domain
) USING domain
ORDER BY hits DESC
LIMIT 10
SETTINGS joined_subquery_requires_alias = 0;
2022-09-27 12:33:09 +00:00
{% if join_algorithm not in ['full_sorting_merge', 'grace_hash'] -%}
2022-05-20 12:00:37 +00:00
SELECT CounterID FROM test.visits ARRAY JOIN Goals.ID WHERE CounterID = 942285 ORDER BY CounterID;
SELECT
CounterID,
hits,
visits
FROM
(
SELECT
(CounterID % 100000) AS CounterID,
count() AS hits
FROM test.hits
GROUP BY CounterID
) ANY FULL OUTER JOIN
(
SELECT
(CounterID % 100000) AS CounterID,
sum(Sign) AS visits
FROM test.visits
GROUP BY CounterID
HAVING visits > 0
) USING CounterID
WHERE hits = 0 OR visits = 0
ORDER BY
hits + visits * 10 DESC,
CounterID ASC
LIMIT 20
SETTINGS any_join_distinct_right_table_keys = 1, joined_subquery_requires_alias = 0;
SELECT
CounterID,
hits,
visits
FROM
(
SELECT
(CounterID % 100000) AS CounterID,
count() AS hits
FROM test.hits
GROUP BY CounterID
) ANY LEFT JOIN
(
SELECT
(CounterID % 100000) AS CounterID,
sum(Sign) AS visits
FROM test.visits
GROUP BY CounterID
HAVING visits > 0
) USING CounterID
WHERE hits = 0 OR visits = 0
ORDER BY
hits + visits * 10 DESC,
CounterID ASC
LIMIT 20
SETTINGS any_join_distinct_right_table_keys = 1, joined_subquery_requires_alias = 0;
SELECT
CounterID,
hits,
visits
FROM
(
SELECT
(CounterID % 100000) AS CounterID,
count() AS hits
FROM test.hits
GROUP BY CounterID
) ANY RIGHT JOIN
(
SELECT
(CounterID % 100000) AS CounterID,
sum(Sign) AS visits
FROM test.visits
GROUP BY CounterID
HAVING visits > 0
) USING CounterID
WHERE hits = 0 OR visits = 0
ORDER BY
hits + visits * 10 DESC,
CounterID ASC
LIMIT 20
SETTINGS any_join_distinct_right_table_keys = 1, joined_subquery_requires_alias = 0;
SELECT
CounterID,
hits,
visits
FROM
(
SELECT
(CounterID % 100000) AS CounterID,
count() AS hits
FROM test.hits
GROUP BY CounterID
) ANY INNER JOIN
(
SELECT
(CounterID % 100000) AS CounterID,
sum(Sign) AS visits
FROM test.visits
GROUP BY CounterID
HAVING visits > 0
) USING CounterID
WHERE hits = 0 OR visits = 0
ORDER BY
hits + visits * 10 DESC,
CounterID ASC
LIMIT 20
SETTINGS any_join_distinct_right_table_keys = 1, joined_subquery_requires_alias = 0;
2022-04-20 08:39:31 +00:00
SELECT UserID, pp.Key1, pp.Key2, ParsedParams.Key1 FROM test.hits ARRAY JOIN ParsedParams AS pp WHERE CounterID = 1704509 ORDER BY UserID, EventTime, pp.Key1, pp.Key2 LIMIT 100;
2022-04-20 08:39:31 +00:00
SELECT UserID, pp.Key1, pp.Key2, ParsedParams.Key1 FROM test.hits LEFT ARRAY JOIN ParsedParams AS pp WHERE CounterID = 1704509 ORDER BY UserID, EventTime, pp.Key1, pp.Key2 LIMIT 100;
SELECT a.*, b.* FROM
(
SELECT number AS k FROM system.numbers LIMIT 10
) AS a
ANY INNER JOIN
(
SELECT number * 2 AS k, number AS joined FROM system.numbers LIMIT 10
) AS b
2022-04-21 10:07:44 +00:00
USING k ORDER BY joined
SETTINGS any_join_distinct_right_table_keys = 1;
2022-05-20 12:00:37 +00:00
{% endif -%}
SELECT a.*, b.* FROM
(
SELECT number AS k FROM system.numbers LIMIT 10
) AS a
ALL INNER JOIN
(
SELECT intDiv(number, 2) AS k, number AS joined FROM system.numbers LIMIT 10
) AS b
2022-04-21 10:07:44 +00:00
USING k ORDER BY joined;
2022-05-20 12:00:37 +00:00
2022-09-27 12:33:09 +00:00
SET max_bytes_in_join = 0;
{% endfor -%}