mirror of
https://github.com/FirebirdSQL/firebird-qa.git
synced 2025-01-22 21:43:06 +01:00
131 lines
3.6 KiB
Python
131 lines
3.6 KiB
Python
#coding:utf-8
|
|
#
|
|
# id: bugs.core_4675
|
|
# title: Conditions like WHERE <field> = <cursor>.<field> do not use existing index
|
|
# decription:
|
|
# tracker_id: CORE-4675
|
|
# min_versions: ['3.0']
|
|
# versions: 3.0
|
|
# qmid: None
|
|
|
|
import pytest
|
|
from firebird.qa import db_factory, isql_act, Action
|
|
|
|
# version: 3.0
|
|
# resources: None
|
|
|
|
substitutions_1 = []
|
|
|
|
init_script_1 = """
|
|
commit;
|
|
set transaction no wait;
|
|
recreate table t1(id int primary key using index pk_t1_id, x int, y int);
|
|
commit;
|
|
|
|
set transaction no wait;
|
|
recreate table t2(id int primary key using index pk_t2_id, x int, y int);
|
|
commit;
|
|
|
|
insert into t1
|
|
select r, mod(r, 10), (r/100)*100
|
|
from (
|
|
select row_number()over() r
|
|
from rdb$types a, (select 1 i from rdb$types rows 40) b
|
|
rows 1000
|
|
);
|
|
commit;
|
|
create index t1_x on t1(x);
|
|
commit;
|
|
|
|
insert into t2 select * from t1;
|
|
commit;
|
|
|
|
create index t2_x on t2(x);
|
|
commit;
|
|
"""
|
|
|
|
db_1 = db_factory(from_backup='mon-stat-gathering-3_0.fbk', init=init_script_1)
|
|
|
|
test_script_1 = """
|
|
execute procedure sp_truncate_stat;
|
|
commit;
|
|
execute procedure sp_gather_stat; ------- catch statistics BEFORE measured statement(s)
|
|
commit;
|
|
|
|
set transaction no wait;
|
|
set term ^;
|
|
execute block as
|
|
declare a_x int;
|
|
declare v_id int;
|
|
declare v_x int;
|
|
declare v_y int;
|
|
declare c_upd1 cursor for (select id, x, y from t1 where x = :a_x);
|
|
declare c_upd2 cursor for (select id, x, y from t2 where x = :a_x);
|
|
begin
|
|
a_x = 5;
|
|
|
|
open c_upd1;
|
|
while (1=1) do begin
|
|
fetch c_upd1 into v_id, v_x, v_y;
|
|
if (row_count = 0) then leave;
|
|
update t1 v set y = c_upd1.x, x = c_upd1.y
|
|
where v.id = :v_id; ----------------- ::: key is specified by VARIABLE which has value from FETCH statement
|
|
end
|
|
close c_upd1;
|
|
|
|
open c_upd2;
|
|
while (1=1) do begin
|
|
fetch c_upd2; -- into v_id, v_x, v_y;
|
|
if (row_count = 0) then leave;
|
|
update t2 v set y = c_upd2.x, x = c_upd2.y
|
|
where v.id = c_upd2.id; ------------- ::: key is specified by CURSOR field using "cursor name + dot + field" syntax
|
|
end
|
|
close c_upd2;
|
|
|
|
end
|
|
^ set term ;^
|
|
rollback;
|
|
|
|
execute procedure sp_gather_stat; ------- catch statistics AFTER measured statement(s)
|
|
commit;
|
|
|
|
set list on;
|
|
set width table_name 31;
|
|
|
|
-- Show results (differences of saved monitoring counters):
|
|
-- ========================================================
|
|
|
|
select v.table_name, v.natural_reads, v.indexed_reads
|
|
from v_agg_stat_tabs v
|
|
where upper(v.table_name) in ( upper('T1'), upper('T2') );
|
|
|
|
-- Output for WI-T6.3.0.31374 (Beta 1 official):
|
|
-- TABLE_NAME T1
|
|
-- NATURAL_READS 0
|
|
-- INDEXED_READS 200
|
|
--
|
|
-- TABLE_NAME T2
|
|
-- NATURAL_READS 100000 <<<< this is bad and has been fixed in CORE_4675
|
|
-- INDEXED_READS 100
|
|
|
|
"""
|
|
|
|
act_1 = isql_act('db_1', test_script_1, substitutions=substitutions_1)
|
|
|
|
expected_stdout_1 = """
|
|
TABLE_NAME T1
|
|
NATURAL_READS 0
|
|
INDEXED_READS 200
|
|
|
|
TABLE_NAME T2
|
|
NATURAL_READS 0
|
|
INDEXED_READS 200
|
|
"""
|
|
|
|
@pytest.mark.version('>=3.0')
|
|
def test_1(act_1: Action):
|
|
act_1.expected_stdout = expected_stdout_1
|
|
act_1.execute()
|
|
assert act_1.clean_expected_stdout == act_1.clean_stdout
|
|
|