mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
Test right join in 02725_any_join_single_row, style code changes
This commit is contained in:
parent
0f0958f82d
commit
bdb192cf27
@ -556,7 +556,7 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE bool insertAll(const HashJoin &, Map & map, KeyGetter & key_getter, Block * stored_block, size_t i, Arena & pool)
|
||||
static ALWAYS_INLINE void insertAll(const HashJoin &, Map & map, KeyGetter & key_getter, Block * stored_block, size_t i, Arena & pool)
|
||||
{
|
||||
auto emplace_result = key_getter.emplaceKey(map, i, pool);
|
||||
|
||||
@ -567,10 +567,9 @@ namespace
|
||||
/// The first element of the list is stored in the value of the hash table, the rest in the pool.
|
||||
emplace_result.getMapped().insert({stored_block, i}, pool);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE bool insertAsof(HashJoin & join, Map & map, KeyGetter & key_getter, Block * stored_block, size_t i, Arena & pool,
|
||||
static ALWAYS_INLINE void insertAsof(HashJoin & join, Map & map, KeyGetter & key_getter, Block * stored_block, size_t i, Arena & pool,
|
||||
const IColumn & asof_column)
|
||||
{
|
||||
auto emplace_result = key_getter.emplaceKey(map, i, pool);
|
||||
@ -580,7 +579,6 @@ namespace
|
||||
if (emplace_result.isInserted())
|
||||
time_series_map = new (time_series_map) typename Map::mapped_type(createAsofRowRef(asof_type, join.getAsofInequality()));
|
||||
(*time_series_map)->insert(asof_column, stored_block, i);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@ -599,7 +597,9 @@ namespace
|
||||
|
||||
auto key_getter = createKeyGetter<KeyGetter, is_asof_join>(key_columns, key_sizes);
|
||||
|
||||
is_inserted = false;
|
||||
/// For ALL and ASOF join always insert values
|
||||
is_inserted = !mapped_one || is_asof_join;
|
||||
|
||||
for (size_t i = 0; i < rows; ++i)
|
||||
{
|
||||
if (has_null_map && (*null_map)[i])
|
||||
@ -615,11 +615,11 @@ namespace
|
||||
continue;
|
||||
|
||||
if constexpr (is_asof_join)
|
||||
is_inserted |= Inserter<Map, KeyGetter>::insertAsof(join, map, key_getter, stored_block, i, pool, *asof_column);
|
||||
Inserter<Map, KeyGetter>::insertAsof(join, map, key_getter, stored_block, i, pool, *asof_column);
|
||||
else if constexpr (mapped_one)
|
||||
is_inserted |= Inserter<Map, KeyGetter>::insertOne(join, map, key_getter, stored_block, i, pool);
|
||||
else
|
||||
is_inserted |= Inserter<Map, KeyGetter>::insertAll(join, map, key_getter, stored_block, i, pool);
|
||||
Inserter<Map, KeyGetter>::insertAll(join, map, key_getter, stored_block, i, pool);
|
||||
}
|
||||
return map.getBufferSizeInCells();
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
Join(ANY, LEFT, key) 0 1
|
||||
Join(ANY, LEFT, key) 1 1
|
||||
Join(ANY, LEFT, key) 1 1
|
||||
1
|
||||
1
|
||||
1
|
||||
|
@ -1,26 +1,41 @@
|
||||
CREATE TABLE join_test
|
||||
(
|
||||
`key` UInt64,
|
||||
`value` UInt64
|
||||
)
|
||||
ENGINE = Join(ANY, LEFT, key);
|
||||
DROP TABLE IF EXISTS join_test;
|
||||
DROP TABLE IF EXISTS join_test_right;
|
||||
|
||||
CREATE TABLE join_test ( `key` UInt64, `value` UInt64 ) ENGINE = Join(ANY, LEFT, key);
|
||||
|
||||
-- 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;
|
||||
|
||||
INSERT INTO join_test (key, value) SELECT 1, number FROM numbers(1);
|
||||
|
||||
|
||||
-- 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;
|
||||
|
||||
INSERT INTO join_test (key, value) SELECT 1, number FROM numbers(1);
|
||||
INSERT INTO join_test (key, value) SELECT 1, number FROM numbers(1);
|
||||
-- Insert some more rows with the same key
|
||||
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
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user