6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-23 05:53:06 +01:00
firebird-qa/tests/functional/tabloid/test_join_transformation_004.py

99 lines
3.3 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-02-04 19:05:19 +01:00
"""
ID: tabloid.join-transformation-04
TITLE: Check ability of outer join simplification.
DESCRIPTION:
Two datasources are involved in the null-rejecting predicate in the WHERE-filtering.
Because of DISJUNCTION usage ('where ... OR ...'), replacement of outer join with
inner one is possible only for part of query that is BEFORE (left-side) of first DS.
This means that we can not simplify LOJ of 'c' and 'd' datasources - see code below.
FBTEST: functional.tabloid.join_transformation_004
"""
2021-04-26 20:07:00 +02:00
2022-02-04 19:05:19 +01:00
import pytest
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-02-04 19:05:19 +01:00
db = db_factory(from_backup='join-transformations.fbk')
2021-04-26 20:07:00 +02:00
2022-02-04 19:05:19 +01:00
test_script = """
2021-04-26 20:07:00 +02:00
execute procedure sp_fill( 35, 30 );
-- ^ ^- probability of assign each field on each row to NULL (percent).
-- +- number of rows in each of tables t1...t6
commit;
execute procedure sp_recalc_idx_stat;
commit;
2022-02-04 19:05:19 +01:00
2021-04-26 20:07:00 +02:00
set list on;
set term ^;
execute block returns(result varchar(50)) as
begin
select result
from sp_run(
---------------------- Query-1 (not simplified)
-- NB: we have to make "padding" of null literals up to 6 fields
-- if query returns less columns:
'select a.id, b.id, c.id, d.id, null, null
from (t1 a left join t2 b using(x,y) )
left ----------------------------------------- [1]
join (
2022-02-04 19:05:19 +01:00
t3 c
2021-04-26 20:07:00 +02:00
left ------------------------------------- [2]: this can NOT be replaced with INNER because of disjunction expr in WHERE-filtering
2022-02-04 19:05:19 +01:00
join t4 d using(x,y)
2021-04-26 20:07:00 +02:00
) using(x,y)
where c.u>0 or d.v>0'
-- ^-------------------------------------- !!!
,
---------------------- Query-2 (simplified and we assume that it ALWAYS produces the same result as Q1)
'select a.id, b.id, c.id, d.id, null, null
from (t1 a left join t2 b using(x,y) )
2022-02-04 19:05:19 +01:00
INNER
2021-04-26 20:07:00 +02:00
join (
2022-02-04 19:05:19 +01:00
t3 c
left
join t4 d using(x,y)
2021-04-26 20:07:00 +02:00
) using(x,y)
where c.u>0 or d.v>0'
, 0 ------------------------------------ nr_total: when 0 then do NOT run sp_fill because we already do have data for checking
) into result;
suspend;
if ( result not containing 'Passed' ) then
2022-02-04 19:05:19 +01:00
-- this context variable serves as 'flag' to show
2021-04-26 20:07:00 +02:00
-- problematic data (see following EB):
2022-02-04 19:05:19 +01:00
rdb$set_context('USER_SESSION', 'FAULT', '1');
2021-04-26 20:07:00 +02:00
end
^
execute block returns( failed_on varchar(255) ) as
begin
-- When queries are NOT equal on some data then we have to output
-- rows from all tables in order to reproduce this trouble later:
if ( rdb$get_context('USER_SESSION', 'FAULT') = '1' ) then
begin
2022-02-04 19:05:19 +01:00
for
select dml from sp_show_data
2021-04-26 20:07:00 +02:00
into failed_on
do
suspend;
end
end
^
set term ^;
"""
2021-04-26 20:07:00 +02:00
2022-02-04 19:05:19 +01:00
act = isql_act('db', test_script)
2021-04-26 20:07:00 +02:00
2022-02-04 19:05:19 +01:00
expected_stdout = """
2021-04-26 20:07:00 +02:00
RESULT Passed.
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=3.0')
2022-02-04 19:05:19 +01:00
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute()
assert act.clean_stdout == act.clean_expected_stdout