|
4 | 4 | ID: issue-2548 |
5 | 5 | ISSUE: 2548 |
6 | 6 | TITLE: Query plan is missing for the long query |
7 | | -DESCRIPTION: |
| 7 | +DESCRIPTION: test creates table with one index and generates query like: |
| 8 | + select * from ... where |
| 9 | + exists(select ...) and |
| 10 | + exists(select ...) and |
| 11 | + exists(select ...) and |
| 12 | + ... |
| 13 | + -- where number of sub-queries is defined by variable SUBQRY_COUNT |
| 14 | + Then we open cursor and ask to show execution plan (in traditional form). |
| 15 | + Plan must have SUBQRY_COUNT lines with the same content: 'PLAN (T1 INDEX (T1_X))' |
8 | 16 | JIRA: CORE-2115 |
9 | 17 | FBTEST: bugs.core_2115 |
| 18 | +NOTES: |
| 19 | + [07.09.2023] pzotov |
| 20 | + 1. Refactored because old query did use "IN(...)" predicate with lot of literals. |
| 21 | + This query became non-actual since IN-algorithm was changed in |
| 22 | + https://github.com/FirebirdSQL/firebird/commit/0493422c9f729e27be0112ab60f77e753fabcb5b |
| 23 | + ("Better processing and optimization if IN <list> predicates (#7707)") |
| 24 | + 2. Although firebird-driver and firebird-qa assumes to be used under FB 3.x+, generated script |
| 25 | + was also checked on FB 2.0.7.13318 and FB 2.1.7.18553. Both these old versions can NOT produce |
| 26 | + any output after SUBQRY_COUNT >= 97. |
| 27 | + 3. Upper limit for SUBQRY_COUNT currently still the same: 256. After exceeding of this, we get: |
| 28 | + "SQLSTATE = 54001 ... -Too many Contexts of Relation/Procedure/Views. Maximum allowed is 256" |
10 | 29 | """ |
11 | 30 |
|
12 | 31 | import pytest |
13 | | -from zipfile import Path |
14 | 32 | from firebird.qa import * |
15 | 33 |
|
16 | | -db = db_factory() |
| 34 | +init_sql = """ |
| 35 | + create sequence g; |
| 36 | + recreate table t1( |
| 37 | + x smallint |
| 38 | + ); |
| 39 | + commit; |
| 40 | + insert into t1 select mod(gen_id(g,1), 256) from rdb$types,(select 1 i from rdb$types rows 10); |
| 41 | + commit; |
| 42 | + create index t1_x on t1(x); |
| 43 | + commit; |
| 44 | +""" |
| 45 | +db = db_factory(init = init_sql) |
17 | 46 |
|
18 | 47 | act = python_act('db') |
19 | 48 |
|
20 | 49 | @pytest.mark.version('>=3.0') |
21 | | -def test_1(act: Action): |
22 | | - # Read script and expected stdout from zip file |
23 | | - datafile = Path(act.files_dir / 'core_2115.zip', |
24 | | - at='tmp_core_2115_queries_with_long_plans.sql') |
25 | | - act.script = datafile.read_text() |
26 | | - datafile = Path(act.files_dir / 'core_2115.zip', |
27 | | - at='tmp_core_2115_check_txt_of_long_plans.log') |
28 | | - act.expected_stdout = datafile.read_text() |
29 | | - act.execute() |
| 50 | +def test_1(act: Action, capsys): |
| 51 | + |
| 52 | + SUBQRY_COUNT = 256 |
| 53 | + test_sql = """ |
| 54 | +select 1 as c |
| 55 | +from t1 |
| 56 | +where x = 0 and |
| 57 | + """ |
| 58 | + |
| 59 | + |
| 60 | + test_sql += '\n'.join( ( f'exists(select 1 from t1 where x = {i}) and' for i in range(SUBQRY_COUNT-1) ) ) |
| 61 | + test_sql += '\n1=1' |
| 62 | + |
| 63 | + with act.db.connect() as con: |
| 64 | + cur = con.cursor() |
| 65 | + ps = cur.prepare(test_sql) |
| 66 | + print(ps.plan) |
| 67 | + |
| 68 | + expected_stdout = '\n'.join( ('PLAN (T1 INDEX (T1_X))' for i in range(SUBQRY_COUNT)) ) |
| 69 | + #assert '' == capsys.readouterr().out |
30 | 70 | assert act.clean_stdout == act.clean_expected_stdout |
0 commit comments