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

88 lines
2.4 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-1967-postfix
ISSUE: 1967
TITLE: Unnecessary index scan happens when the same index is mapped to both WHERE and ORDER BY clauses
DESCRIPTION:
JIRA: CORE-1550
FBTEST: bugs.core_1550_postfix
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
-- sent to dimitr 30.09.14 at 22:09
set term ^;
execute block as
begin
execute statement 'drop sequence g';
when any do begin end
end^
set term ;^
commit;
create sequence g; commit;
recreate table td(id int primary key using index td_pk, f01 int, f02 int); commit;
recreate table tm(id int); commit;
insert into tm select gen_id(g,1) from rdb$types rows 100;
commit;
insert into td(id, f01, f02) select id, (select min(id) from tm), gen_id(g,1) from tm; commit;
create index td_f01_non_unq on td(f01);
create unique index td_f01_f02_unq on td(f01, f02); -- ### NB: compound UNIQUE index presens here beside of PK ###
commit;
set planonly;
-- 1. Check for usage when only PK fields are involved:
select *
from tm m
where exists(
2022-01-20 17:32:14 +01:00
select * from td d where m.id = d.id
2021-04-26 20:07:00 +02:00
order by d.id --------------------------- ### this "useless" order by should prevent from bitmap creation in 3.0+
);
-- Ineffective plan was here:
-- PLAN (D ORDER TD_PK INDEX (TD_PK))
-- ... ^
-- |
-- +-----> BITMAP created!
2022-01-20 17:32:14 +01:00
2021-04-26 20:07:00 +02:00
-- 2. Check for usage when fields from UNIQUE index are involved:
select *
from tm m
where exists(
2022-01-20 17:32:14 +01:00
select * from td d
where m.id = d.f01 and d.f02 = 10
2021-04-26 20:07:00 +02:00
order by d.f01, d.f02 ------------------- ### this "useless" order by should prevent from bitmap creation in 3.0+
);
-- Ineffective plan was here:
-- PLAN (D ORDER TD_F01_F02_UNQ INDEX (TD_F01_F02_UNQ))
-- ... ^
-- |
-- +-----> BITMAP created!
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
PLAN (D ORDER TD_PK)
PLAN (M NATURAL)
PLAN (D ORDER TD_F01_F02_UNQ)
PLAN (M NATURAL)
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