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

185 lines
4.4 KiB
Python

#coding:utf-8
#
# id: bugs.gh_6873
# title: SIMILAR TO does not use index when pattern starts with non-wildcard character (in contrary to LIKE)
# decription:
# https://github.com/FirebirdSQL/firebird/issues/6873
#
# Checked on: 5.0.0.113.
#
# tracker_id:
# min_versions: ['5.0']
# versions: 5.0
# qmid: None
import pytest
from firebird.qa import db_factory, isql_act, Action
# version: 5.0
# resources: None
substitutions_1 = []
init_script_1 = """"""
db_1 = db_factory(sql_dialect=3, init=init_script_1)
test_script_1 = """
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_1 = isql_act('db_1', test_script_1, substitutions=substitutions_1)
expected_stdout_1 = """
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_1: Action):
act_1.expected_stdout = expected_stdout_1
act_1.execute()
assert act_1.clean_stdout == act_1.clean_expected_stdout