Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

startsWith() does not use the PK index #5310

Closed
alex-zaitsev opened this issue May 16, 2019 · 1 comment · Fixed by #5919
Closed

startsWith() does not use the PK index #5310

alex-zaitsev opened this issue May 16, 2019 · 1 comment · Fixed by #5919
Assignees
Labels
easy task Good for first contributors performance

Comments

@alex-zaitsev
Copy link
Contributor

Describe the bug

startsWith(a, 'a') does not use the index, though functionally identical like 'a%' does. This is confusing.

How to reproduce

create table test_index (a String) Engine = MergeTree PARTITION BY tuple() ORDER BY a;

INSERT INTO test_index (a) values ('a');

select count() from test_index where startsWith(a, 'abc') settings force_primary_key=1;

Received exception from server (version 19.4.3):
Code: 277. DB::Exception: Received from localhost:9000, ::1. DB::Exception: Primary key (a) is not used and setting 'force_primary_key' is set.. 

Similar query with LIKE:

select count() from test_index where a like 'abc%' settings force_primary_key=1;

Ok.

Expected behaviour

startsWith to use index if possible.

@alex-zaitsev alex-zaitsev added the bug Confirmed user-visible misbehaviour in official release label May 16, 2019
@alexey-milovidov alexey-milovidov added performance and removed bug Confirmed user-visible misbehaviour in official release labels May 16, 2019
@alexey-milovidov
Copy link
Member

alexey-milovidov commented May 16, 2019

How to implement:
KeyCondition.cpp, look at atom_map and its usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy task Good for first contributors performance
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants