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

91 lines
2.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-5712
ISSUE: 5712
TITLE: Cache physical numbers of often used data pages to reduce number of fetches of pointer pages
DESCRIPTION:
We create table with single field, add several rows and create index.
Number of these rows must be enough to fit all of them in the single data page.
Than we do loop and query on every iteration one row, using PLAN INDEX.
Only _first_ iteration should lead to reading PP (and this requires 1 fetch),
but all subseq. must require to read only DP. This should refect in trace as:
* 4 fetches for 1st statement;
* 3 fetches for statements starting with 2nd.
Distinct number of fetches are accumulated in Python dict, and is displayed finally.
We should have TWO distinct elements in this dict, and numbers in their values must
differ at (N-1), where N = number of rows in the table.
JIRA: CORE-5441
FBTEST: bugs.core_5441
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
init_script = """
2021-04-26 20:07:00 +02:00
recreate table test(x int primary key);
commit;
insert into test(x) select r from (
select row_number()over() r
2021-04-26 20:07:00 +02:00
from rdb$types a,rdb$types b
rows 10
)
2021-04-26 20:07:00 +02:00
order by rand();
commit;
set term ^;
2021-04-26 20:07:00 +02:00
create procedure sp_test as
declare n int;
declare c int;
begin
2021-04-26 20:07:00 +02:00
n = 10;
while( n > 0 ) do
2021-04-26 20:07:00 +02:00
begin
execute statement ( 'select 1 from test where x = ? rows 1' ) ( :n ) into c;
n = n - 1;
end
end^
2021-04-26 20:07:00 +02:00
set term ;^
commit;
"""
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
db = db_factory(page_size=8192, init=init_script)
2022-01-25 22:55:48 +01:00
act = python_act('db')
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
fetches=3 occured 9 times
fetches=4 occured 1 times
"""
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
trace = ['time_threshold = 0',
'log_initfini = false',
'log_statement_finish = true',
'include_filter = "%(select % from test where x = ?)%"',
]
2021-04-26 20:07:00 +02:00
@pytest.mark.trace
@pytest.mark.version('>=3.0.2')
2022-01-25 22:55:48 +01:00
def test_1(act: Action, capsys):
with act.trace(db_events=trace), act.db.connect() as con:
c = con.cursor()
c.call_procedure('sp_test')
# Process trace
fetches_distinct_amounts = {}
2022-01-25 22:55:48 +01:00
for line in act.trace_log:
if 'fetch(es)' in line:
words = line.split()
for k in range(len(words)):
if words[k].startswith('fetch'):
amount = words[k - 1]
if not amount in fetches_distinct_amounts:
fetches_distinct_amounts[amount] = 1
else:
fetches_distinct_amounts[amount] += 1
for k, v in sorted(fetches_distinct_amounts.items()):
print(f'fetches={k} occured {v} times')
# Check
2022-01-25 22:55:48 +01:00
act.expected_stdout = expected_stdout
act.stdout = capsys.readouterr().out
assert act.clean_stdout == act.clean_expected_stdout