Skip to content

Commit 1384000

Browse files
committed
Add the test bugs.core_5602 from fbt-repository.
1 parent bc118bc commit 1384000

File tree

1 file changed

+228
-0
lines changed

1 file changed

+228
-0
lines changed

tests/bugs/core_5602_test.py

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
#coding:utf-8
2+
3+
"""
4+
ID: issue-5868
5+
ISSUE: 5868
6+
TITLE: Slow changes on domain
7+
DESCRIPTION:
8+
Poor performance was reproduced after discuss with Vlad (14.09.2017).
9+
Test restores DB which has 20 tables, each with 20 fields based on domain
10+
(i.e. 'create table t_NN(f_N bool_emul, ...)', where NN=1,2, ..., 20).
11+
Also it has 20 stored procedures, and each of these SP has 20 input
12+
and 20 output parameters declared as 'type of column t_NN.field_NN'
13+
NOTE. We have to SKIP preparing phase of such DB because DDL vasts
14+
too much time, so this database was created once and then stored as fbk.
15+
After restoring we only run:
16+
1) alter domain drop constraint;
17+
2) commit;
18+
3) alter domain add check;
19+
4) commit;
20+
-- and measure elapsed time of each step (we store time in context variables).
21+
Then we evaluate DATEDIFF() for each of 1...4 steps and two RATIOS:
22+
A) 'alter domain drop constraint' vs commit just after it;
23+
B) 'alter domain add check' vs commit just after it;
24+
25+
RESULTS of dozen measures :
26+
==========================
27+
* on build 31798 (17-aug-2017) ratio for 20 tables, 20 fields and 20 SPs was more than 100
28+
(i.e. 'ALTER DOMAIN ADD | DROP' ran ~100x slower than COMMIT);
29+
* on build 32802 (06-sep-2017) ratio is about 0.1 (YES, 'alter domain' runs FASTER ~10x than commit!)
30+
31+
Threshold in this test is assigned to 1 - I hope it will be enough for all subsequent builds of 3.0 and 4.0.
32+
33+
Checked on:
34+
fb30Cs, build 3.0.3.32802: OK, 5.312s.
35+
FB30SS, build 3.0.3.32802: OK, 4.297s.
36+
FB40CS, build 4.0.0.744: OK, 7.484s.
37+
FB40SS, build 4.0.0.744: OK, 7.140s.
38+
39+
Here is auxiliary batch that allows to get DB with arbitrary number of tables/fields and SPs:
40+
========= start of batch ========
41+
42+
@echo off
43+
setlocal enabledelayedexpansion enableextensions
44+
45+
@rem Required number of TABLES:
46+
set tq=20
47+
48+
@rem Required number of FIELDS in each table (and also this will be equal to number of SP input and output args):
49+
set fq=20
50+
51+
set tmp_ddl=%~dpn0_tmp_ddl.sql
52+
set tmp_run=%~dpn0_tmp_run.sql
53+
54+
@rem Name of test DB that will be recreated each time this batch run:
55+
set dsn=localhost:C:\MIX\firebird\QA\fbt-repo\tmp\c5602.fdb
56+
57+
@rem Which FB we test: 2.5 or 3.0 ?
58+
if .%1.==.25. (
59+
set fbc=C:\MIX\firebird\fb25\bin
60+
) else if .%1.==.30. (
61+
set fbc=C:\MIX\firebird\fb30
62+
) else (
63+
echo Arg #1 must be specified: 'fbc' = 25 ^| 30 - path to FB binaries.
64+
exit
65+
)
66+
67+
if exist C:\MIX\firebird\QA\fbt-repo\tmp\c5602.fdb del C:\MIX\firebird\QA\fbt-repo\tmp\c5602.fdb
68+
69+
echo create database '!dsn!' page_size 8192; | !fbc!\isql -q -z
70+
!fbc!\gfix -w async !dsn!
71+
@rem !fbc!\gstat -h !dsn! | findstr /i /c:date /c:attrib
72+
73+
(
74+
echo set bail on;
75+
echo create domain bool_emul char(1^) check ( value in ('t','f' ^) ^);
76+
echo commit;
77+
echo set autoddl off;
78+
echo commit;
79+
echo.
80+
) >!tmp_ddl!
81+
82+
for /l %%i in (1,1,!tq!) do (
83+
(
84+
85+
echo create table t_%%i(
86+
for /l %%j in (1,1,!fq!) do (
87+
set del=,
88+
if %%j EQU 1 set del=
89+
echo !del!bool_fld_%%j bool_emul
90+
)
91+
echo ^);
92+
93+
echo set term ^^;
94+
echo create or alter procedure p_%%i (
95+
for /l %%j in (1,1,!fq!) do (
96+
set del=,
97+
if %%j EQU 1 set del=
98+
echo !del!inp_%%j type of column t_%%i.bool_fld_%%j
99+
)
100+
echo ^) returns (
101+
for /l %%j in (1,1,!fq!) do (
102+
set del=,
103+
if %%j EQU 1 set del=
104+
echo !del!out_%%j type of column t_%%i.bool_fld_%%j
105+
)
106+
echo ^) as begin
107+
echo suspend;
108+
echo end
109+
echo ^^
110+
echo set term ;^^
111+
echo commit;
112+
113+
echo --------------------
114+
) >>!tmp_ddl!
115+
116+
if %%i EQU !tq! (
117+
echo commit;
118+
) >>!tmp_ddl!
119+
)
120+
121+
!fbc!\isql !dsn! -i !tmp_ddl!
122+
123+
124+
(
125+
echo --set stat on;
126+
echo --set echo on;
127+
echo set autoddl OFF;
128+
echo commit;
129+
echo set term ^^; execute block as begin rdb$set_context('USER_SESSION','DTS_1', current_timestamp^); end ^^ set term ;^^
130+
echo alter domain bool_emul drop constraint;
131+
echo set term ^^; execute block as begin rdb$set_context('USER_SESSION','DTS_2', current_timestamp^); end ^^ set term ;^^
132+
echo commit;
133+
echo set term ^^; execute block as begin rdb$set_context('USER_SESSION','DTS_3', current_timestamp^); end ^^ set term ;^^
134+
echo alter domain bool_emul add check (value in ('t', 'f'^)^);
135+
echo set term ^^; execute block as begin rdb$set_context('USER_SESSION','DTS_4', current_timestamp^); end ^^ set term ;^^
136+
echo commit;
137+
echo set term ^^; execute block as begin rdb$set_context('USER_SESSION','DTS_5', current_timestamp^); end ^^ set term ;^^
138+
echo set list on;
139+
echo select
140+
echo iif(drop_to_commit_ratio ^< 1, 'OK, ACCEPTABLE', '"ALTER DOMAIN DROP CONSTRAINT" too slow: ratio to commit is ' ^|^| drop_to_commit_ratio ^) "DROP CHECK to COMMIT time ratio"
141+
echo ,iif(add_to_commit_ratio ^< 1, 'OK, ACCEPTABLE', '"ALTER DOMAIN ADD CHECK" too slow: ratio to commit is ' ^|^| add_to_commit_ratio ^) "ADD CHECK to COMMIT time ratio"
142+
echo from (
143+
echo select
144+
echo cast(1.0000 * elap_ms_drop_chk/elap_ms_commit_1 as double precision^) as drop_to_commit_ratio
145+
echo ,cast(1.0000 * elap_ms_add_chk/elap_ms_commit_2 as double precision^) as add_to_commit_ratio
146+
echo from (
147+
echo select
148+
echo datediff(millisecond from dts1 to dts2^) as elap_ms_drop_chk
149+
echo ,datediff(millisecond from dts2 to dts3^) as elap_ms_commit_1
150+
echo ,datediff(millisecond from dts3 to dts4^) as elap_ms_add_chk
151+
echo ,datediff(millisecond from dts4 to dts5^) as elap_ms_commit_2
152+
echo from (
153+
echo select
154+
echo cast( rdb$get_context('USER_SESSION','DTS_1'^) as timestamp ^) as dts1
155+
echo ,cast( rdb$get_context('USER_SESSION','DTS_2'^) as timestamp ^) as dts2
156+
echo ,cast( rdb$get_context('USER_SESSION','DTS_3'^) as timestamp ^) as dts3
157+
echo ,cast( rdb$get_context('USER_SESSION','DTS_4'^) as timestamp ^) as dts4
158+
echo ,cast( rdb$get_context('USER_SESSION','DTS_5'^) as timestamp ^) as dts5
159+
echo from rdb$database
160+
echo ^)
161+
echo ^)
162+
echo ^);
163+
echo quit;
164+
)>!tmp_run!
165+
166+
!fbc!\isql !dsn! -n -i !tmp_run!
167+
168+
======== finish of batch ========
169+
JIRA: CORE-5602
170+
FBTEST: bugs.core_5602
171+
"""
172+
173+
import pytest
174+
from firebird.qa import *
175+
176+
db = db_factory(from_backup='core5602.fbk')
177+
178+
test_script = """
179+
set autoddl OFF;
180+
commit;
181+
set term ^; execute block as begin rdb$set_context('USER_SESSION','DTS_1', current_timestamp); end ^ set term ;^
182+
alter domain bool_emul drop constraint;
183+
set term ^; execute block as begin rdb$set_context('USER_SESSION','DTS_2', current_timestamp); end ^ set term ;^
184+
commit;
185+
set term ^; execute block as begin rdb$set_context('USER_SESSION','DTS_3', current_timestamp); end ^ set term ;^
186+
alter domain bool_emul add check (value in ('t', 'f'));
187+
set term ^; execute block as begin rdb$set_context('USER_SESSION','DTS_4', current_timestamp); end ^ set term ;^
188+
commit;
189+
set term ^; execute block as begin rdb$set_context('USER_SESSION','DTS_5', current_timestamp); end ^ set term ;^
190+
set list on;
191+
select
192+
iif(drop_to_commit_ratio < 1, 'OK, ACCEPTABLE', 'ALTER DOMAIN DROP CONSTRAINT runs slowly: ratio to commit is ' || drop_to_commit_ratio ) "DROP CHECK to COMMIT time ratio"
193+
,iif(add_to_commit_ratio < 1, 'OK, ACCEPTABLE', 'ALTER DOMAIN ADD CHECK runs slowly: ratio to commit is ' || add_to_commit_ratio ) "ADD CHECK to COMMIT time ratio"
194+
from (
195+
select
196+
cast(1.0000 * elap_ms_drop_chk/elap_ms_commit_1 as double precision) as drop_to_commit_ratio
197+
,cast(1.0000 * elap_ms_add_chk/elap_ms_commit_2 as double precision) as add_to_commit_ratio
198+
from (
199+
select
200+
datediff(millisecond from dts1 to dts2) as elap_ms_drop_chk
201+
,datediff(millisecond from dts2 to dts3) as elap_ms_commit_1
202+
,datediff(millisecond from dts3 to dts4) as elap_ms_add_chk
203+
,datediff(millisecond from dts4 to dts5) as elap_ms_commit_2
204+
from (
205+
select
206+
cast( rdb$get_context('USER_SESSION','DTS_1') as timestamp ) as dts1
207+
,cast( rdb$get_context('USER_SESSION','DTS_2') as timestamp ) as dts2
208+
,cast( rdb$get_context('USER_SESSION','DTS_3') as timestamp ) as dts3
209+
,cast( rdb$get_context('USER_SESSION','DTS_4') as timestamp ) as dts4
210+
,cast( rdb$get_context('USER_SESSION','DTS_5') as timestamp ) as dts5
211+
from rdb$database
212+
)
213+
)
214+
);
215+
"""
216+
217+
act = isql_act('db', test_script)
218+
219+
expected_stdout = """
220+
DROP CHECK to COMMIT time ratio OK, ACCEPTABLE
221+
ADD CHECK to COMMIT time ratio OK, ACCEPTABLE
222+
"""
223+
224+
@pytest.mark.version('>=3.0.3')
225+
def test_1(act: Action):
226+
act.expected_stdout = expected_stdout
227+
act.execute()
228+
assert act.clean_stdout == act.clean_expected_stdout

0 commit comments

Comments
 (0)