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_5845_test.py

77 lines
1.8 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-26 21:10:46 +01:00
"""
ID: issue-6106
ISSUE: 6106
TITLE: ORDER BY on index can cause suboptimal index choices
DESCRIPTION:
JIRA: CORE-5845
FBTEST: bugs.core_5845
2022-01-26 21:10:46 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
import pytest
from firebird.qa import *
db = db_factory()
test_script = """
recreate table test
(
id1 integer,
id2 integer,
id3 integer,
x numeric(18,2),
constraint pk_test primary key(id1, id2, id3)
);
create index ixa_test__x on test(x);
create index ixa_test__id1_x on test(id1, x);
2021-04-26 20:07:00 +02:00
commit;
2022-01-26 21:10:46 +01:00
--------------------------------------------------------------------------------
2021-04-26 20:07:00 +02:00
set plan on;
2022-01-26 21:10:46 +01:00
select *
from test t
where t.id1=1 and t.x>0
2021-04-26 20:07:00 +02:00
;
2022-01-26 21:10:46 +01:00
--plan (t index (ixa_test__id1_x))
--index ixa_test__id1_x is used
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
--------------------------------------------------------------------------------
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
select * from test t
where t.id1=1 and t.x>0
order by t.id1, t.id2, t.id3
2021-04-26 20:07:00 +02:00
;
2022-01-26 21:10:46 +01:00
--plan (t order pk_test index (ixa_test__x))
--index ixa_test__x - suboptimal
--as you can see adding order by which consume some index (pk_test)
--cause suboptimal choice of index (ixa_test__x)
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
--------------------------------------------------------------------------------
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
--if query is changed to order by not by index
--plan sort (t index (ixa_test__id1_x))
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
select * from test t
where
t.id1=1
and t.x>0
order by t.id1+0, t.id2, t.id3
2021-04-26 20:07:00 +02:00
;
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
act = isql_act('db', test_script)
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
expected_stdout = """
2021-04-26 20:07:00 +02:00
PLAN (T INDEX (IXA_TEST__ID1_X))
PLAN SORT (T INDEX (IXA_TEST__ID1_X))
PLAN SORT (T INDEX (IXA_TEST__ID1_X))
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=3.0.4')
2022-01-26 21:10:46 +01:00
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute()
assert act.clean_stdout == act.clean_expected_stdout