Skip to content

Try fix pk in tuple performance#12062

Merged
CurtizJ merged 6 commits intoClickHouse:masterfrom
nvartolomei:nv/set-index-tuple-types
Jul 2, 2020
Merged

Try fix pk in tuple performance#12062
CurtizJ merged 6 commits intoClickHouse:masterfrom
nvartolomei:nv/set-index-tuple-types

Conversation

@nvartolomei
Copy link
Copy Markdown
Contributor

@nvartolomei nvartolomei commented Jun 30, 2020

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):
Fix "#10574 Index not used for IN operator with literals", performance regression introduced around v19.3.

Detailed description / Documentation draft:
Fixes #10574.

The problem is that prepared sets are built correctly, it is a hash map of key -> set
where key is a hash of AST and list of data types (when we a list of
tuples of literals).

However, when the key is built from the index to try and find if there
exists a prepared set that would match it looks for data types of the
primary key (see how data_types is populated) because the primary key
has only one field (v in my example) it can not find the prepared set.

The patch looks for any prepared indexes where data types match for the
subset of fields found in primary key, we are not interested in other
fields anyway for the purpose of primary key pruning.

Possible approach for fixing #10574

The problem is that prepared sets are built correctly, it is a hash map of key -> set
where key is a hash of AST and list of data types (when we a list of
tuples of literals).

However, when the key is built from the index to try and find if there
exists a prepared set that would match it looks for data types of the
primary key (see how data_types is populated) because the primary key
has only one field (v in my example) it can not find the prepared set.

The patch looks for any prepared indexes where data types match for the
subset of fields found in primary key, we are not interested in other
fields anyway for the purpose of primary key pruning.
@blinkov blinkov added the pr-performance Pull request with some performance improvements label Jun 30, 2020
@CurtizJ CurtizJ self-assigned this Jun 30, 2020
Copy link
Copy Markdown
Member

@CurtizJ CurtizJ left a comment

Choose a reason for hiding this comment

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

LGTM

@CurtizJ
Copy link
Copy Markdown
Member

CurtizJ commented Jul 1, 2020

Also you can use setting force_primary_key in tests.

@nvartolomei nvartolomei marked this pull request as ready for review July 1, 2020 16:18
@nvartolomei nvartolomei requested a review from CurtizJ July 1, 2020 16:18
@CurtizJ CurtizJ merged commit 71059e4 into ClickHouse:master Jul 2, 2020
@nvartolomei nvartolomei deleted the nv/set-index-tuple-types branch July 2, 2020 17:47
@filimonov
Copy link
Copy Markdown
Contributor

Let's try to backport it since it's a regression when updating from pre 19.1

@filimonov filimonov added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Jul 27, 2020
CurtizJ added a commit that referenced this pull request Jul 27, 2020
Backport #12062 to 20.3: Try fix pk in tuple performance
CurtizJ added a commit that referenced this pull request Jul 27, 2020
Backport #12062 to 20.5: Try fix pk in tuple performance
CurtizJ added a commit that referenced this pull request Jul 27, 2020
Backport #12062 to 20.4: Try fix pk in tuple performance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Index not used for IN operator with literals

4 participants