6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 21:43:06 +01:00
firebird-qa/tests/bugs/gh_6873_test.py

174 lines
4.0 KiB
Python

#coding:utf-8
"""
ID: issue-6873
ISSUE: 6873
TITLE: SIMILAR TO does not use index when pattern starts with non-wildcard character (in contrary to LIKE)
DESCRIPTION:
FBTEST: bugs.gh_6873
"""
import pytest
from firebird.qa import *
db = db_factory()
test_script = """
create collation name_coll_ci for utf8 from unicode case insensitive;
create collation name_coll_ci_ai for utf8 from unicode case insensitive accent insensitive;
create domain dm_name_ci as varchar(10) character set utf8 collate name_coll_ci;
create domain dm_name_ci_ai as varchar(10) character set utf8 collate name_coll_ci_ai;
recreate table test(
id int generated by default as identity constraint test_pk primary key
,x1 varchar(10)
,y1 varchar(10)
,x2 dm_name_ci
,y2 dm_name_ci
,x3 dm_name_ci_ai
,y3 dm_name_ci_ai
);
insert into test(x1, x2, x3) values('', '', '' );
insert into test(x1, x2, x3) values('a', 'Ⱥ', 'Ă' );
insert into test(x1, x2, x3) values(' a', ' Ⱥ', ' Ă' );
insert into test(x1, x2, x3) values('aa', 'ȺȺ', 'ĂĂ' );
update test set y1 = x1, y2 = x2, y3 = x3;
commit;
create index test_x1_asc on test(x1);
create descending index test_y1_dec on test(y1);
create index test_x2_asc on test(x2);
create descending index test_y2_dec on test(y2);
create index test_x3_asc on test(x3);
create descending index test_y3_dec on test(y3);
commit;
set list on;
set plan on;
-- All following statements must use apropriate INDEXES:
--set echo on;
select id from test where x1 similar to 'a%';
select id from test where x1 similar to 'a_';
select id from test where x1 similar to 'a';
select id from test where y1 similar to 'a%';
select id from test where y1 similar to 'a_';
select id from test where y1 similar to 'a';
select id from test where x2 similar to '%';
select id from test where x2 similar to 'ⱥ_';
select id from test where x2 similar to '';
select id from test where y2 similar to '%';
select id from test where y2 similar to 'ⱥ_';
select id from test where y2 similar to '';
select id from test where x3 similar to 'Â%';
select id from test where x3 similar to 'Â_';
select id from test where x3 similar to 'Â';
select id from test where y3 similar to 'Â%';
select id from test where y3 similar to 'Â_';
select id from test where y3 similar to 'Â';
"""
act = isql_act('db', test_script)
expected_stdout = """
PLAN (TEST INDEX (TEST_X1_ASC))
ID 2
ID 4
PLAN (TEST INDEX (TEST_X1_ASC))
ID 4
PLAN (TEST INDEX (TEST_X1_ASC))
ID 2
PLAN (TEST INDEX (TEST_Y1_DEC))
ID 2
ID 4
PLAN (TEST INDEX (TEST_Y1_DEC))
ID 4
PLAN (TEST INDEX (TEST_Y1_DEC))
ID 2
PLAN (TEST INDEX (TEST_X2_ASC))
ID 2
ID 4
PLAN (TEST INDEX (TEST_X2_ASC))
ID 4
PLAN (TEST INDEX (TEST_X2_ASC))
ID 2
PLAN (TEST INDEX (TEST_Y2_DEC))
ID 2
ID 4
PLAN (TEST INDEX (TEST_Y2_DEC))
ID 4
PLAN (TEST INDEX (TEST_Y2_DEC))
ID 2
PLAN (TEST INDEX (TEST_X3_ASC))
ID 2
ID 4
PLAN (TEST INDEX (TEST_X3_ASC))
ID 4
PLAN (TEST INDEX (TEST_X3_ASC))
ID 2
PLAN (TEST INDEX (TEST_Y3_DEC))
ID 2
ID 4
PLAN (TEST INDEX (TEST_Y3_DEC))
ID 4
PLAN (TEST INDEX (TEST_Y3_DEC))
ID 2
"""
@pytest.mark.version('>=5.0')
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute()
assert act.clean_stdout == act.clean_expected_stdout