ClickHouse/tests/queries/0_stateless/02725_any_join_single_row.sql

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

42 lines
2.2 KiB
MySQL
Raw Normal View History

DROP TABLE IF EXISTS join_test;
DROP TABLE IF EXISTS join_test_right;
2023-05-04 14:08:03 +00:00
CREATE TABLE join_test ( `key` UInt64, `value` UInt64 ) ENGINE = Join(ANY, LEFT, key);
-- Save table size before inserting any rows
2023-05-04 14:08:03 +00:00
CREATE TEMPORARY TABLE initial_table_size AS
SELECT engine_full, total_rows, total_bytes FROM system.tables WHERE (name = 'join_test') AND (database = currentDatabase());
-- Check that table size is less than 100K
2023-05-04 14:08:03 +00:00
SELECT engine_full, total_rows, total_bytes < 100_000 FROM initial_table_size;
INSERT INTO join_test (key, value) SELECT 1, number FROM numbers(1);
-- Save table size after inserting one row
2023-05-04 14:08:03 +00:00
CREATE TEMPORARY TABLE one_row_table_size AS
SELECT engine_full, total_rows, total_bytes FROM system.tables WHERE (name = 'join_test') AND (database = currentDatabase());
-- Check that table size is less than 2x after inserting one row
2023-05-04 14:08:03 +00:00
SELECT engine_full, total_rows, total_bytes < 2 * (SELECT total_bytes FROM initial_table_size) FROM one_row_table_size;
-- Insert some more rows with the same key
2023-05-04 14:08:03 +00:00
INSERT INTO join_test (key, value) SELECT 1, number FROM numbers(1);
INSERT INTO join_test (key, value) SELECT 1, number FROM numbers(10_000);
-- Check that rows with the same key are not duplicated
2023-05-04 14:08:03 +00:00
SELECT engine_full, total_rows, total_bytes == (SELECT total_bytes FROM one_row_table_size) FROM system.tables WHERE (name = 'join_test') AND (database = currentDatabase());
-- For RIGHT join we save all rows from the right table
CREATE TABLE join_test_right ( `key` UInt64, `value` UInt64 ) ENGINE = Join(ANY, RIGHT, key);
INSERT INTO join_test_right (key, value) SELECT 1, number FROM numbers(1);
INSERT INTO join_test_right (key, value) SELECT 1, number FROM numbers(1);
INSERT INTO join_test_right (key, value) SELECT 1, number FROM numbers(1);
SELECT count() == 3 FROM (SELECT 1 as key) t1 ANY RIGHT JOIN join_test_right ON t1.key = join_test_right.key;
INSERT INTO join_test_right (key, value) SELECT 1, number FROM numbers(7);
SELECT count() == 10 FROM (SELECT 1 as key) t1 ANY RIGHT JOIN join_test_right ON t1.key = join_test_right.key;
SELECT count() == 10 FROM (SELECT 2 as key) t1 ANY RIGHT JOIN join_test_right ON t1.key = join_test_right.key;
DROP TABLE IF EXISTS join_test;
DROP TABLE IF EXISTS join_test_right;