Nikita Mikhaylov 2024-04-02 16:38:18 +00:00
parent 478cabee22
commit a4a56a9b6c
2 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,41 @@
-- https://github.com/ClickHouse/ClickHouse/issues/44153
DROP TABLE IF EXISTS parent;
DROP TABLE IF EXISTS join_table_1;
DROP TABLE IF EXISTS join_table_2;
CREATE TABLE parent(
a_id Int64,
b_id Int64,
c_id Int64,
created_at Int64
)
ENGINE=MergeTree()
ORDER BY (a_id, b_id, c_id, created_at);
CREATE TABLE join_table_1(
a_id Int64,
b_id Int64
)
ENGINE=MergeTree()
ORDER BY (a_id, b_id);
CREATE TABLE join_table_2(
c_id Int64,
created_at Int64
)
ENGINE=MergeTree()
ORDER BY (c_id, created_at);
WITH with_table as (
SELECT p.a_id, p.b_id, p.c_id FROM parent p
LEFT JOIN join_table_1 jt1 ON jt1.a_id = p.a_id AND jt1.b_id = p.b_id
LEFT JOIN join_table_2 jt2 ON jt2.c_id = p.c_id
WHERE
p.a_id = 0 AND (jt2.c_id = 0 OR p.created_at = 0)
)
SELECT p.a_id, p.b_id, COUNT(*) as f_count FROM with_table
GROUP BY p.a_id, p.b_id;
DROP TABLE IF EXISTS parent;
DROP TABLE IF EXISTS join_table_1;
DROP TABLE IF EXISTS join_table_2;