

-- Save table size before inserting any rows
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
SELECT engine_full, total_rows, total_bytes < 100_000 FROM initial_table_size;

-- Save table size after inserting one row
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
SELECT engine_full, total_rows, total_bytes < 2 * (SELECT total_bytes FROM initial_table_size) FROM one_row_table_size;

-- Check that rows with the same key are not duplicated
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());
