6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-23 05:53:06 +01:00
firebird-qa/tests/bugs/core_4665_test.py

114 lines
3.5 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-24 20:27:02 +01:00
"""
ID: issue-1602
ISSUE: 1602
TITLE: Wrong result when use "where <field_C> STARTING WITH <:value> ORDER BY <field_N>" and field_C is leading part of compound index key: { field_C, field_N }
DESCRIPTION:
JIRA: CORE-4665
"""
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
import pytest
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
db = db_factory()
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
test_script = """
2021-04-26 20:07:00 +02:00
recreate table test (id int, unit varchar(10), y int, z int);
commit;
delete from test;
2022-01-24 20:27:02 +01:00
2021-04-26 20:07:00 +02:00
insert into test( id, unit, y, z) values (1, 'foo', 9999, 23636);
insert into test( id, unit, y, z) values (2, 'foo', 8888, 22520);
insert into test( id, unit, y, z) values (3, 'foo', 5555, 21822);
insert into test( id, unit, y, z) values (4, 'foo', 3333, 17682);
2022-01-24 20:27:02 +01:00
2021-04-26 20:07:00 +02:00
insert into test( id, unit, y, z) values (5, 'fooo', 1111, 22);
insert into test( id, unit, y, z) values (6, 'fooo', 111, 222);
insert into test( id, unit, y, z) values (7, 'fooo', 11, 2222);
insert into test( id, unit, y, z) values (8, 'fooo', 1, 22222);
commit;
2022-01-24 20:27:02 +01:00
2021-04-26 20:07:00 +02:00
create index test_unit_y_asc on test( unit, y );
2022-01-24 20:27:02 +01:00
commit;
2021-04-26 20:07:00 +02:00
set plan on;
2022-01-24 20:27:02 +01:00
2021-04-26 20:07:00 +02:00
select id, t.unit, t.y, t.z
from test t
where t.unit||'' starting with 'foo'
order by t.y||'';
2022-01-24 20:27:02 +01:00
2021-04-26 20:07:00 +02:00
select id, t.unit, t.y, t.z
from test t
where t.unit starting with 'foo'
2022-01-24 20:27:02 +01:00
order by t.y;
2021-04-26 20:07:00 +02:00
set plan off;
2022-01-24 20:27:02 +01:00
2021-04-26 20:07:00 +02:00
commit;
drop index test_unit_y_asc;
commit;
2022-01-24 20:27:02 +01:00
2021-04-26 20:07:00 +02:00
create descending index test_unit_y_desc on test( unit, y);
2022-01-24 20:27:02 +01:00
commit;
2021-04-26 20:07:00 +02:00
set plan on;
select id, t.unit, t.y, t.z
from test t
where t.unit starting with 'foo'
2022-01-24 20:27:02 +01:00
order by t.y;
2021-04-26 20:07:00 +02:00
set plan off;
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
act = isql_act('db', test_script, substitutions=[('=.*', '')])
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
expected_stdout = """
2021-04-26 20:07:00 +02:00
PLAN SORT (T NATURAL)
2022-01-24 20:27:02 +01:00
ID UNIT Y Z
============ ========== ============ ============
8 fooo 1 22222
7 fooo 11 2222
6 fooo 111 222
5 fooo 1111 22
4 foo 3333 17682
3 foo 5555 21822
2 foo 8888 22520
1 foo 9999 23636
2021-04-26 20:07:00 +02:00
PLAN SORT (T INDEX (TEST_UNIT_Y_ASC))
2022-01-24 20:27:02 +01:00
ID UNIT Y Z
============ ========== ============ ============
8 fooo 1 22222
7 fooo 11 2222
6 fooo 111 222
5 fooo 1111 22
4 foo 3333 17682
3 foo 5555 21822
2 foo 8888 22520
1 foo 9999 23636
2021-04-26 20:07:00 +02:00
PLAN SORT (T INDEX (TEST_UNIT_Y_DESC))
2022-01-24 20:27:02 +01:00
ID UNIT Y Z
============ ========== ============ ============
8 fooo 1 22222
7 fooo 11 2222
6 fooo 111 222
5 fooo 1111 22
4 foo 3333 17682
3 foo 5555 21822
2 foo 8888 22520
1 foo 9999 23636
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=3.0')
2022-01-24 20:27:02 +01:00
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute()
assert act.clean_stdout == act.clean_expected_stdout
2021-04-26 20:07:00 +02:00