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

81 lines
2.0 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-5432
ISSUE: 5432
TITLE: Regression: LEFT JOIN incorrectly pushes COALESCE into the inner stream causing wrong results
DESCRIPTION:
JIRA: CORE-5149
FBTEST: bugs.core_5149
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
-- Confirmed: wrong result on WI-V3.0.0.32380; works fine on LI-V3.0.0.32381.
2022-01-25 22:55:48 +01:00
recreate table t_stock (
tnr varchar(16),
amount integer
);
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
recreate table t_main (
tnr varchar(16) primary key using index t_main_tnr,
minb integer
);
alter table t_stock
add constraint fk_t_stock_1
foreign key (tnr) references t_main (tnr)
2021-04-26 20:07:00 +02:00
on delete cascade on update cascade
using index t_stock_tnr
;
commit;
2022-01-25 22:55:48 +01:00
insert into t_main (tnr, minb) values ('aaa', 0);
insert into t_main (tnr, minb) values ('bbb', 10);
insert into t_main (tnr, minb) values ('ccc', 10);
insert into t_main (tnr, minb) values ('ddd', 10);
insert into t_stock (tnr, amount) values ('aaa', 100);
insert into t_stock (tnr, amount) values ('bbb', 5);
insert into t_stock (tnr, amount) values ('ccc', 15);
commit;
2021-04-26 20:07:00 +02:00
set list on;
2022-01-25 22:55:48 +01:00
select
2021-04-26 20:07:00 +02:00
a.tnr
,a.minb
,b.amount as b_amount
,coalesce(b.amount,0) as coalesce_b_amt
2022-01-25 22:55:48 +01:00
from t_main a
2021-04-26 20:07:00 +02:00
left join t_stock b on a.tnr = b.tnr
where a.minb > coalesce(b.amount,0)
order by a.tnr
;
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
TNR bbb
MINB 10
B_AMOUNT 5
COALESCE_B_AMT 5
TNR ddd
MINB 10
B_AMOUNT <null>
COALESCE_B_AMT 0
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=3.0')
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