Skip to content

Do not write expired columns by TTL after subsequent merges - #37570

Merged
CurtizJ merged 6 commits into
ClickHouse:masterfrom
azat:column-ttl-expired-fix
Jun 7, 2022
Merged

CurtizJ merged 6 commits into
ClickHouse:masterfrom
azat:column-ttl-expired-fix

Conversation

@azat

@azat azat commented May 26, 2022 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Do not write expired columns by TTL after subsequent merges (before only first merge/optimize of the part will not write expired by TTL columns, all other will do)

Usually second merge do not perform TTL, since everything is up to date,
however in this case TTLTransform is not used, and hence expired_columns
will not be filled for new part, and so those columns will be written
with default values.

You will find reproducer in details (and in the test):

Details
create table ttl_02262 (date Date, key Int, value String TTL date + interval 1 month) engine=MergeTree order by key settings min_bytes_for_wide_part=0, min_rows_for_wide_part=0;
insert into ttl_02262 values ('2010-01-01', 2010, 'foo');
# ls -l .server/data/default/ttl_02262/all_*
.server/data/default/ttl_02262/all_1_1_0:
total 48
-rw-r----- 1 root root 335 May 26 14:19 checksums.txt
-rw-r----- 1 root root  76 May 26 14:19 columns.txt
-rw-r----- 1 root root   1 May 26 14:19 count.txt
-rw-r----- 1 root root  28 May 26 14:19 date.bin
-rw-r----- 1 root root  48 May 26 14:19 date.mrk2
-rw-r----- 1 root root  10 May 26 14:19 default_compression_codec.txt
-rw-r----- 1 root root  30 May 26 14:19 key.bin
-rw-r----- 1 root root  48 May 26 14:19 key.mrk2
-rw-r----- 1 root root   8 May 26 14:19 primary.idx
-rw-r----- 1 root root  99 May 26 14:19 ttl.txt
-rw-r----- 1 root root  30 May 26 14:19 value.bin
-rw-r----- 1 root root  48 May 26 14:19 value.mrk2
optimize table ttl_02262 final;
.server/data/default/ttl_02262/all_1_1_1:
total 40
-rw-r----- 1 root root 279 May 26 14:19 checksums.txt
-rw-r----- 1 root root  61 May 26 14:19 columns.txt
-rw-r----- 1 root root   1 May 26 14:19 count.txt
-rw-r----- 1 root root  28 May 26 14:19 date.bin
-rw-r----- 1 root root  48 May 26 14:19 date.mrk2
-rw-r----- 1 root root  10 May 26 14:19 default_compression_codec.txt
-rw-r----- 1 root root  30 May 26 14:19 key.bin
-rw-r----- 1 root root  48 May 26 14:19 key.mrk2
-rw-r----- 1 root root   8 May 26 14:19 primary.idx
-rw-r----- 1 root root  81 May 26 14:19 ttl.txt
optimize table ttl_02262 final;
.server/data/default/ttl_02262/all_1_1_2:
total 48
-rw-r----- 1 root root 349 May 26 14:20 checksums.txt
-rw-r----- 1 root root  76 May 26 14:20 columns.txt
-rw-r----- 1 root root   1 May 26 14:20 count.txt
-rw-r----- 1 root root  28 May 26 14:20 date.bin
-rw-r----- 1 root root  48 May 26 14:20 date.mrk2
-rw-r----- 1 root root  10 May 26 14:20 default_compression_codec.txt
-rw-r----- 1 root root  30 May 26 14:20 key.bin
-rw-r----- 1 root root  48 May 26 14:20 key.mrk2
-rw-r----- 1 root root   8 May 26 14:20 primary.idx
-rw-r----- 1 root root  81 May 26 14:20 ttl.txt
-rw-r----- 1 root root  27 May 26 14:20 value.bin
-rw-r----- 1 root root  48 May 26 14:20 value.mrk2

And now we have value.* for all_1_1_2, this should not happen.

Cc: @CurtizJ

azat added 6 commits May 26, 2022 20:14
Previously you cannot distinguish non-initialized finished with
initialized to false, so update() cannot do the correct thing.

Rename the field to avoid hidden usage.

Signed-off-by: Azat Khuzhin <[email protected]>
Usually second merge do not perform TTL, since everything is up to date,
however in this case TTLTransform is not used, and hence expired_columns
will not be filled for new part, and so those columns will be written
with default values.

Avoid this, by manually filling expired_columns.

Here is a simpler reproducer:

Simple reproducer:

    ```sql
    create table ttl_02262 (date Date, key Int, value String TTL date + interval 1 month) engine=MergeTree order by key settings min_bytes_for_wide_part=0, min_rows_for_wide_part=0;
    insert into ttl_02262 values ('2010-01-01', 2010, 'foo');
    ```

    ```sh
    # ls -l .server/data/default/ttl_02262/all_*
    .server/data/default/ttl_02262/all_1_1_0:
    total 48
    -rw-r----- 1 root root 335 May 26 14:19 checksums.txt
    -rw-r----- 1 root root  76 May 26 14:19 columns.txt
    -rw-r----- 1 root root   1 May 26 14:19 count.txt
    -rw-r----- 1 root root  28 May 26 14:19 date.bin
    -rw-r----- 1 root root  48 May 26 14:19 date.mrk2
    -rw-r----- 1 root root  10 May 26 14:19 default_compression_codec.txt
    -rw-r----- 1 root root  30 May 26 14:19 key.bin
    -rw-r----- 1 root root  48 May 26 14:19 key.mrk2
    -rw-r----- 1 root root   8 May 26 14:19 primary.idx
    -rw-r----- 1 root root  99 May 26 14:19 ttl.txt
    -rw-r----- 1 root root  30 May 26 14:19 value.bin
    -rw-r----- 1 root root  48 May 26 14:19 value.mrk2
    ```

    ```sql
    optimize table ttl_02262 final;
    ```

    ```sh
    .server/data/default/ttl_02262/all_1_1_1:
    total 40
    -rw-r----- 1 root root 279 May 26 14:19 checksums.txt
    -rw-r----- 1 root root  61 May 26 14:19 columns.txt
    -rw-r----- 1 root root   1 May 26 14:19 count.txt
    -rw-r----- 1 root root  28 May 26 14:19 date.bin
    -rw-r----- 1 root root  48 May 26 14:19 date.mrk2
    -rw-r----- 1 root root  10 May 26 14:19 default_compression_codec.txt
    -rw-r----- 1 root root  30 May 26 14:19 key.bin
    -rw-r----- 1 root root  48 May 26 14:19 key.mrk2
    -rw-r----- 1 root root   8 May 26 14:19 primary.idx
    -rw-r----- 1 root root  81 May 26 14:19 ttl.txt
    ```

    ```sql
    optimize table ttl_02262 final;
    ```

    ```sh
    .server/data/default/ttl_02262/all_1_1_2:
    total 48
    -rw-r----- 1 root root 349 May 26 14:20 checksums.txt
    -rw-r----- 1 root root  76 May 26 14:20 columns.txt
    -rw-r----- 1 root root   1 May 26 14:20 count.txt
    -rw-r----- 1 root root  28 May 26 14:20 date.bin
    -rw-r----- 1 root root  48 May 26 14:20 date.mrk2
    -rw-r----- 1 root root  10 May 26 14:20 default_compression_codec.txt
    -rw-r----- 1 root root  30 May 26 14:20 key.bin
    -rw-r----- 1 root root  48 May 26 14:20 key.mrk2
    -rw-r----- 1 root root   8 May 26 14:20 primary.idx
    -rw-r----- 1 root root  81 May 26 14:20 ttl.txt
    -rw-r----- 1 root root  27 May 26 14:20 value.bin
    -rw-r----- 1 root root  48 May 26 14:20 value.mrk2
    ```

And now we have `value.*` for all_1_1_2, this should not happen.

Signed-off-by: Azat Khuzhin <[email protected]>
@robot-clickhouse robot-clickhouse added the pr-improvement Pull request with some product improvements label May 26, 2022
@azat

azat commented May 30, 2022

Copy link
Copy Markdown
Member Author

@azat

azat commented Jun 2, 2022 •

Copy link
Copy Markdown
Member Author

@CurtizJ maybe you can take a look?

P.S. initially I tagged you in the description, but I placed the closing tag for details incorrectly, and I guess that's why you have not been notified.

@CurtizJ CurtizJ self-assigned this Jun 2, 2022
@CurtizJ

CurtizJ commented Jun 7, 2022

Copy link
Copy Markdown
Member

Stress tests: #37569

@CurtizJ
CurtizJ merged commit ef6f5a6 into ClickHouse:master Jun 7, 2022
@azat
azat deleted the column-ttl-expired-fix branch June 7, 2022 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants