6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 13:33:07 +01:00
firebird-qa/tests/bugs/core_1482_test.py

77 lines
1.9 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-20 17:32:14 +01:00
"""
ID: issue-1898
ISSUE: 1898
TITLE: Make optimizer to consider ORDER BY optimization when making decision about join order
DESCRIPTION:
JIRA: CORE-1482
FBTEST: bugs.core_1482
2022-01-20 17:32:14 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-20 17:32:14 +01:00
import pytest
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-20 17:32:14 +01:00
db = db_factory()
2021-04-26 20:07:00 +02:00
2022-01-20 17:32:14 +01:00
test_script = """
2021-04-26 20:07:00 +02:00
recreate table tcolor(id int , name varchar(20) );
recreate table thorses(id int, color_id int, name varchar(20));
commit;
2022-01-20 17:32:14 +01:00
2021-04-26 20:07:00 +02:00
set term ^;
execute block as
declare i int;
declare n_main int = 50;
declare ratio int = 1000;
begin
i = 0;
while (i < n_main) do
begin
i = i + 1;
insert into tcolor(id, name)
values (:i, 'color #' || :i);
end
i = 0;
while (i < n_main * ratio) do
begin
i = i + 1;
insert into thorses(id, color_id, name)
values (:i, mod(:i, :n_main)+1, 'horse #' || :i);
end
end
^
set term ;^
commit;
2022-01-20 17:32:14 +01:00
2021-04-26 20:07:00 +02:00
create index tcolor_id on tcolor(id);
create index thorses_color_id on thorses(color_id);
-- this index was forgotten in previous revisions:
create index thorses_id on thorses(id);
commit;
2022-01-20 17:32:14 +01:00
2021-04-26 20:07:00 +02:00
set list on;
select (select count(*) from tcolor) colors_cnt, (select count(*) from thorses) horses_cnt
from rdb$database;
set planonly;
-- in 2.1 and 2.5: PLAN SORT (JOIN (M NATURAL, D INDEX (THORSES_COLOR_ID))) -- doesn`t see 'rows 1'
-- in 3.0 plan should CHANGE and take in account 'rows N' limit:
select * from tcolor m join thorses d on m.id = d.color_id order by d.id rows 1;
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-20 17:32:14 +01:00
act = isql_act('db', test_script)
2021-04-26 20:07:00 +02:00
2022-01-20 17:32:14 +01:00
expected_stdout = """
2021-04-26 20:07:00 +02:00
COLORS_CNT 50
HORSES_CNT 50000
PLAN JOIN (D ORDER THORSES_ID, M INDEX (TCOLOR_ID))
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=3.0')
2022-01-20 17:32:14 +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