Merge pull request #45061 from kitaisreal/range-hashed-dictionary-update-field-primary-key-fix

RangeHashedDictionary update field primary key fix
This commit is contained in:
Alexey Milovidov 2023-01-10 05:11:12 +03:00 committed by GitHub
commit dcae391210
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 1 deletions

View File

@ -688,7 +688,9 @@ void RangeHashedDictionary<dictionary_key_type>::updateData()
static constexpr size_t range_columns_size = 2;
auto pipe = source_ptr->loadUpdatedAll();
mergeBlockWithPipe<dictionary_key_type>(
/// Use complex dictionary key type to count range columns as part of complex primary key during update
mergeBlockWithPipe<DictionaryKeyType::Complex>(
dict_struct.getKeysSize() + range_columns_size,
*update_field_loaded_block,
std::move(pipe));

View File

@ -0,0 +1,11 @@
1 101 200 2022-12-26 11:38:34
1 0 100 2022-12-26 11:38:34
2 1000 10000 2022-12-26 11:38:34
2 0 999 2022-12-26 11:38:34
2022-12-26 11:38:34
--
1 101 200 2022-12-26 11:38:34
1 0 100 2022-12-26 11:38:34
2 1000 10000 2022-12-26 11:38:34
2 0 999 2022-12-26 11:38:34
2022-12-26 11:38:34

View File

@ -0,0 +1,37 @@
DROP TABLE IF EXISTS test_table;
CREATE TABLE test_table
(
uid Int64,
start Int64,
end Int64,
insert_time DateTime
) ENGINE = MergeTree ORDER BY (uid, start);
DROP DICTIONARY IF EXISTS test_dictionary;
CREATE DICTIONARY test_dictionary
(
start Int64,
end Int64,
insert_time DateTime,
uid Int64
) PRIMARY KEY uid
LAYOUT(RANGE_HASHED())
RANGE(MIN start MAX end)
SOURCE(CLICKHOUSE(TABLE 'test_table' UPDATE_FIELD 'insert_time' UPDATE_LAG 10))
LIFETIME(MIN 1 MAX 2);
INSERT INTO test_table VALUES (1, 0, 100, '2022-12-26 11:38:34'), (1, 101, 200, '2022-12-26 11:38:34'), (2, 0, 999, '2022-12-26 11:38:34'), (2, 1000, 10000, '2022-12-26 11:38:34');
SELECT * FROM test_dictionary;
SELECT dictGet('test_dictionary', 'insert_time', toUInt64(1), 10);
SELECT sleep(3) format Null;
SELECT sleep(3) format Null;
SELECT '--';
SELECT * FROM test_dictionary;
SELECT dictGet('test_dictionary', 'insert_time', toUInt64(1), 10);
DROP DICTIONARY test_dictionary;
DROP TABLE test_table;