Skip to content

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

@pavel-zotov

Description

@pavel-zotov
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)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions