Skip to content
New issue

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

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

Already on GitHub? # to your account

SIMILAR TO should use index when pattern starts with non-wildcard character (as LIKE does) #6873

Closed
pavel-zotov opened this issue Jun 27, 2021 · 0 comments

Comments

@pavel-zotov
Copy link

SQL> recreate table test(id int generated by default as identity constraint test_pk primary key, x varchar(50));
SQL> create index test_x on test(x);
SQL> insert into test(x) values('');
SQL> insert into test(x) values('a');
SQL> insert into test(x) values(' a');
SQL> insert into test(x) values('aa');
SQL> commit;
SQL> set plan on;
SQL> set planonly;
SQL> select * from test where x like 'a%';

PLAN (TEST INDEX (TEST_X))
SQL> select * from test where x like 'a_';

PLAN (TEST INDEX (TEST_X))
SQL> select * from test where x like 'a';

PLAN (TEST INDEX (TEST_X))
SQL> ------------------------------------
SQL> select * from test where x similar to 'a%';

PLAN (TEST NATURAL)
SQL> select * from test where x similar to 'a_';

PLAN (TEST NATURAL)
SQL> select * from test where x similar to 'a';

PLAN (TEST NATURAL)
@asfernandes asfernandes self-assigned this Jun 27, 2021
@dyemanov dyemanov changed the title SIMILAR TO does not use index when pattern starts with non-wildcard character (in contrary to LIKE) SIMILAR TO should use index when pattern starts with non-wildcard character (as LIKE does) Jun 17, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment