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

73 lines
1.8 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-25 22:55:48 +01:00
"""
ID: issue-5751
ISSUE: 5751
TITLE: Available indices are not used in some cases if ORDER BY expression is a filtered one
DESCRIPTION:
JIRA: CORE-5481
FBTEST: bugs.core_5481
2022-01-25 22:55:48 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
import pytest
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
db = db_factory()
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
test_script = """
2021-04-26 20:07:00 +02:00
recreate view v_test as select 1 x from rdb$database;
commit;
2022-01-25 22:55:48 +01:00
recreate table balances
(
balanceid bigint not null,
orgaccountid bigint not null,
balancedate date not null
);
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
recreate table org_accounts
(
orgaccountid bigint not null primary key
);
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
alter table balances add constraint pk_balances primary key (balanceid);
alter table balances add constraint fk_balances_orgaccounts foreign key (orgaccountid) references org_accounts (orgaccountid);
alter table balances add constraint balances_balancedate_orgaccount unique (orgaccountid, balancedate);
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
create descending index balances_balancedate_desc on balances (balancedate);
2021-04-26 20:07:00 +02:00
recreate view v_test as
select b.*
2022-01-25 22:55:48 +01:00
from balances b
where
orgaccountid=18 and
balancedate<='01.01.2017'
2021-04-26 20:07:00 +02:00
order by balancedate desc
rows 1
;
commit;
set plan on;
select * from v_test;
commit;
ALTER TABLE BALANCES DROP CONSTRAINT BALANCES_BALANCEDATE_ORGACCOUNT;
commit;
select * from v_test; -- plan here should remains the same!
commit;
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
act = isql_act('db', test_script)
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
expected_stdout = """
2021-04-26 20:07:00 +02:00
PLAN (V_TEST B ORDER BALANCES_BALANCEDATE_DESC INDEX (FK_BALANCES_ORGACCOUNTS))
PLAN (V_TEST B ORDER BALANCES_BALANCEDATE_DESC INDEX (FK_BALANCES_ORGACCOUNTS))
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=3.0.4')
2022-01-25 22:55:48 +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