6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 21:43:06 +01:00
firebird-qa/tests/bugs/core_4904_test.py

80 lines
2.8 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-24 20:27:02 +01:00
"""
ID: issue-5196
ISSUE: 5196
TITLE: Index corruption when add data in long-key-indexed field
DESCRIPTION:
In order to check ticket issues this test does following:
1. Change on test database FW to OFF - this will increase DML performance.
2. Create table with indexed field of length = maximum that is allowed by
current FB implementation (page_size / 4 - 9 bytes).
3. Try to insert enough number of records in this table - this should cause
runtime exception SQLSTATE = 54000, "Maximum index level reached"
4. Start validation of database: index should NOT be corrupted in its report.
JIRA: CORE-4904
FBTEST: bugs.core_4904
2022-01-24 20:27:02 +01:00
"""
2021-04-26 20:07:00 +02:00
import pytest
2022-01-24 20:27:02 +01:00
from firebird.qa import *
2021-11-26 19:20:43 +01:00
from firebird.driver import DbWriteMode
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
substitutions = [('[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9]', ''),
('Maximum index .* reached', 'Maximum index reached'),
('Relation [0-9]{3,4}', 'Relation'), ('After line .*', ''),
('-At block line: [\\d]+, col: [\\d]+', '-At block line')]
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
# Test depends on 4K page_size !!!
db = db_factory(page_size=4096)
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
act = python_act('db', substitutions=substitutions)
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
long_keys_cmd = """
recreate table test(s varchar(1015)); -- with THIS length of field following EB will get exception very fast.
create index test_s on test(s);
commit;
set term ^;
execute block as
begin
insert into test(s)
select rpad('', 1015, uuid_to_char(gen_uuid()) )
from rdb$types, rdb$types
rows 50000; -- this is extra-huge reserve; exception should raise when about 120-130 rows will be inserted.
end
^
set term ;^
commit;
"""
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
expected_stdout = """
2021-04-26 20:07:00 +02:00
Statement failed, SQLSTATE = 54000
Implementation limit exceeded
-Maximum index level reached
-At block line: 3, col: 7
Validation started
Relation (TEST)
process pointer page 0 of 1
Index 1 (TEST_S)
Relation (TEST) is ok
Validation finished
2021-11-26 19:20:43 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=3.0')
2022-01-24 20:27:02 +01:00
def test_1(act: Action, capsys):
2021-11-26 19:20:43 +01:00
# Move database to FW = OFF in order to increase speed of insertions and output its header info:
2022-01-24 20:27:02 +01:00
with act.connect_server() as srv:
srv.database.set_write_mode(database=act.db.db_path, mode=DbWriteMode.ASYNC)
2021-11-26 19:20:43 +01:00
# Preparing script for ISQL that will do inserts with long keys:
2022-01-24 20:27:02 +01:00
act.expected_stderr = "We expect errors"
act.isql(switches=[], input=long_keys_cmd)
print(act.stdout)
print(act.stderr)
2021-11-26 19:20:43 +01:00
# Run validation after ISQL will finish (with runtime exception due to implementation limit exceeding):
2022-01-24 20:27:02 +01:00
srv.database.validate(database=act.db.db_path, lock_timeout=1, callback=print)
2021-11-26 19:20:43 +01:00
# Check
2022-01-24 20:27:02 +01:00
act.expected_stdout = expected_stdout
act.stdout = capsys.readouterr().out
assert act.clean_stdout == act.clean_expected_stdout