Skip to content

Select final - #15938

Merged
CurtizJ merged 12 commits into
ClickHouse:masterfrom
Avogar:select_final
Nov 3, 2020
Merged

CurtizJ merged 12 commits into
ClickHouse:masterfrom
Avogar:select_final

Conversation

@Avogar

@Avogar Avogar commented Oct 13, 2020 •

Copy link
Copy Markdown
Member

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Do not merge parts across partitions in SELECT FINAL

Detailed description / Documentation draft:
Define a new setting do_not_merge_across_partitions_select_final. If it's true we will merge parts only with the same partition, moreover, if there is only one part in partition and it's level > 0 we won't merge it. This resolves #11722

@robot-clickhouse robot-clickhouse added the pr-performance Pull request with some performance improvements label Oct 13, 2020
@UnamedRus

Copy link
Copy Markdown
Contributor

Define a new setting do_not_merge_across_partitions_select_final. If it's true we will merge parts only with the same partition, moreover, if there is only one part in partition and it's level > 0 we won't merge it.

There is a possibility that partition was attached from ./detached dir or from another table and already has level > 0 and duplicates, so it isn't a reliable way to check this, or we would need to reset the level of that partition to zero in that kind of parts manipulation.

@alexey-milovidov

alexey-milovidov commented Oct 13, 2020 •

Copy link
Copy Markdown
Member

Maybe better to have simple rule: if one part in partition - do not postprocess it.

@CurtizJ CurtizJ self-assigned this Oct 20, 2020

@CurtizJ CurtizJ left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be useful to add a perf test and also to check the difference in performance with case, when all partitions are merged.

@Avogar

Avogar commented Oct 21, 2020

Copy link
Copy Markdown
Member Author

It will be useful to add a perf test and also to check the difference in performance with case, when all partitions are merged.

@CurtizJ I've never written perf tests before, can you explain what should I do in performance test? Just make a query with SELECT ... FINAL? And how to check the difference in performance in different cases in such tests?

@CurtizJ

CurtizJ commented Oct 21, 2020 •

Copy link
Copy Markdown
Member

You can find examples of performance tests in tests/performance. Test is a .xml file with bunch of queries for measuring time of their executing and possible some additional queries for preparation. Also you can set specific settings for tests. A good example, where all sections exist. It's recommended for execution time of query to be in 0.1-1s.

Yes, just add a query with SELECT ... FINAL and your setting to check that in the future performance of this behaviour won't be broken.

And how to check the difference in performance in different cases in such tests?

It's ok to compare two modes of FINAL locally, just to be sure, that performance has been improved.

@Avogar

Avogar commented Oct 22, 2020

Copy link
Copy Markdown
Member Author

You can find examples of performance tests in tests/performance. Test is a .xml file with bunch of queries for measuring time of their executing and possible some additional queries for preparation. Also you can set specific settings for tests. A good example, where all sections exist. It's recommended for execution time of query to be in 0.1-1s.

Yes, just add a query with SELECT ... FINAL and your setting to check that in the future performance of this behaviour won't be broken.

And how to check the difference in performance in different cases in such tests?

It's ok to compare two modes of FINAL locally, just to be sure, that performance has been improved.

Thanks for clear explanation! I will try to do it at this week

@Avogar

Avogar commented Oct 28, 2020 •

Copy link
Copy Markdown
Member Author

@CurtizJ I see this exception in my perf test:
DB::Exception: Unknown setting do_not_merge_across_partitions_select_final.
But I added this setting in this pr and I can't understand the reason of exception, it works locally, do you know what's wrong?

@alexey-milovidov

alexey-milovidov commented Oct 29, 2020 •

Copy link
Copy Markdown
Member

@Avogar It because performance test runs two servers: old and new.
This error is Ok for old server (no further actions required).

@CurtizJ

CurtizJ commented Nov 3, 2020

Copy link
Copy Markdown
Member

00840_long_concurrent_select_and_drop_deadlock is broken in master.

@CurtizJ
CurtizJ merged commit 85ab1e9 into ClickHouse:master Nov 3, 2020
@den-crane

den-crane commented Jan 19, 2021 •

Copy link
Copy Markdown
Contributor

hm, I don't see much improvement:

3.611s VS 2.063s.

CREATE TABLE T (p Int64, d Date, some_col String)
Engine=ReplacingMergeTree 
Partition by toYYYYMM(d)
Order by (p, d);


insert into T select number, '2020-01-01', '' from numbers(100000000);
insert into T select number, '2020-01-01', 'updated' from numbers(100000000);

optimize table T final;

select distinct(_part) from T;
┌─_part──────────┐
│ 202001_1_192_4 │
└────────────────┘

select max(d) from T final where some_col = 'updated';
Elapsed: 3.611 sec. Processed 100.00 million rows, 2.60 GB (27.69 million rows/s., 720.04 MB/s.)

select max(d) from T final where some_col = 'updated' SETTINGS do_not_merge_across_partitions_select_final = 1;
Elapsed: 2.063 sec. Processed 100.00 million rows, 2.60 GB (48.47 million rows/s., 1.26 GB/s.)

expected:
select max(d) from T  where some_col = 'updated';
Elapsed: 0.202 sec. Processed 100.00 million rows, 1.80 GB (494.28 million rows/s., 8.90 GB/s.)

@Avogar

Avogar commented Jan 21, 2021 •

Copy link
Copy Markdown
Member Author

hm, I don't see much improvement:

Yes, you're right. I forgot to add parallel select in this case. I added it here #19375

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve performance of FINAL modifier for Collapsing/Replacing MergeTree

7 participants