mirror of
https://github.com/FirebirdSQL/firebird-qa.git
synced 2025-01-22 13:33:07 +01:00
106 lines
2.8 KiB
Python
106 lines
2.8 KiB
Python
|
#coding:utf-8
|
||
|
|
||
|
"""
|
||
|
ID: issue-3810
|
||
|
ISSUE: https://github.com/FirebirdSQL/firebird/issues/3810
|
||
|
TITLE: Wrong or missing IS NULL optimization (regression) [CORE3449]
|
||
|
NOTES:
|
||
|
[14.04.2023] pzotov
|
||
|
Confirmed poor performance on 3.0.11.33678 (num of fetches = 10'099).
|
||
|
Checked on 3.0.11.33681 -- all fine, fetches differ for less than 20.
|
||
|
"""
|
||
|
|
||
|
import pytest
|
||
|
from firebird.qa import *
|
||
|
|
||
|
db = db_factory()
|
||
|
|
||
|
test_script = """
|
||
|
set bail on;
|
||
|
create table tmp_tbl1 (fld1 integer, fld2 integer, fld3 integer);
|
||
|
create index tmp_tbl1_fld123 on tmp_tbl1(fld1, fld2, fld3);
|
||
|
create index tmp_tbl1_fld2 on tmp_tbl1(fld2);
|
||
|
commit;
|
||
|
set term ^;
|
||
|
create or alter procedure tmp_sp1 as
|
||
|
declare i integer;
|
||
|
begin
|
||
|
i=0;
|
||
|
while ( i < 10000 ) do begin
|
||
|
i=i+1;
|
||
|
insert into tmp_tbl1 values (1, :i, 2);
|
||
|
end
|
||
|
end
|
||
|
^
|
||
|
set term ;^
|
||
|
commit;
|
||
|
execute procedure tmp_sp1;
|
||
|
commit;
|
||
|
SET STATISTICS INDEX TMP_TBL1_FLD123;
|
||
|
SET STATISTICS INDEX TMP_TBL1_FLD2;
|
||
|
commit;
|
||
|
|
||
|
recreate view v_check as
|
||
|
select i.mon$page_fetches as pg_fetches
|
||
|
from mon$attachments a
|
||
|
left join mon$io_stats i on a.mon$stat_id = i.mon$stat_id and i.mon$stat_group = 1
|
||
|
where
|
||
|
a.mon$attachment_id = current_connection
|
||
|
;
|
||
|
|
||
|
-- set planonly;
|
||
|
set list on;
|
||
|
set term ^;
|
||
|
execute block as
|
||
|
begin
|
||
|
rdb$set_context('USER_SESSION', 'fetches_a', (select pg_fetches from v_check));
|
||
|
end
|
||
|
^
|
||
|
set plan on
|
||
|
^
|
||
|
select count(*) from tmp_tbl1 where fld1=1 and fld2 is null
|
||
|
^
|
||
|
set plan off
|
||
|
^
|
||
|
commit
|
||
|
^
|
||
|
execute block as
|
||
|
begin
|
||
|
rdb$set_context('USER_SESSION', 'fetches_b', (select pg_fetches from v_check));
|
||
|
end
|
||
|
^
|
||
|
set term ;^
|
||
|
|
||
|
select
|
||
|
iif( fetches_b - fetches_a < max_threshold
|
||
|
,'OK, expected'
|
||
|
,'POOR: ' || cast(fetches_b - fetches_a as varchar(12)) || ' - exdeeds threshold = ' || cast(max_threshold as varchar(12))
|
||
|
) as fetches_diff
|
||
|
from (
|
||
|
select
|
||
|
cast(rdb$get_context('USER_SESSION', 'fetches_b') as int) as fetches_b
|
||
|
,cast(rdb$get_context('USER_SESSION', 'fetches_a') as int) as fetches_a
|
||
|
,50 as max_threshold
|
||
|
-- ^
|
||
|
-- |
|
||
|
-- | ###########################
|
||
|
-- +-- ### T H R E S H O L D ###
|
||
|
-- ###########################
|
||
|
from rdb$database
|
||
|
);
|
||
|
"""
|
||
|
|
||
|
act = isql_act('db', test_script)
|
||
|
|
||
|
expected_stdout = """
|
||
|
PLAN (TMP_TBL1 INDEX (TMP_TBL1_FLD123))
|
||
|
COUNT 0
|
||
|
FETCHES_DIFF OK, expected
|
||
|
"""
|
||
|
|
||
|
@pytest.mark.version('>=3.0.11')
|
||
|
def test_1(act: Action):
|
||
|
act.expected_stdout = expected_stdout
|
||
|
act.execute(combine_output = True)
|
||
|
assert act.clean_stdout == act.clean_expected_stdout
|