Skip to content

Commit 7e3ddec

Browse files
committed
Added/Updated tests\functional\tabloid\test_e260ced8.py: see notes
1 parent 1a62a85 commit 7e3ddec

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#coding:utf-8
2+
3+
"""
4+
ID: issue-e260ced8
5+
ISSUE: https://github.com/FirebirdSQL/firebird/commit/5df6668c7bf5a4b27e15f687f8c6cc40e260ced8
6+
TITLE: Allow computable but non-invariant lists to be used for index lookup
7+
DESCRIPTION:
8+
NOTES:
9+
[08.09.2023]
10+
Before improvement explained plan was:
11+
=======
12+
Sub-query
13+
-> Filter
14+
-> Table "T1" as "B" Access By ID
15+
-> Bitmap Or
16+
-> Bitmap Or
17+
-> Bitmap
18+
-> Index "T1_X" Range Scan (full match)
19+
-> Bitmap
20+
-> Index "T1_X" Range Scan (full match)
21+
-> Bitmap
22+
-> Index "T1_X" Range Scan (full match)
23+
Select Expression
24+
-> Filter
25+
-> Table "T1" as "A" Full Scan
26+
=======
27+
After improvement only one (single) line for index "T1_X" must present in explained plan,
28+
and access method must be: Index "T1_X" Full Scan.
29+
Thanks to dimitr for suggestion, see letter 08-sep-2023 09:47.
30+
31+
Test shows explained plan so that leading spaces are replaced in every its line with '#'
32+
(it is desirable to leading indents).
33+
34+
Checked on 5.0.0.1190.
35+
"""
36+
37+
import pytest
38+
from firebird.qa import *
39+
40+
init_sql = """
41+
recreate table t1(
42+
id int primary key,
43+
x int
44+
);
45+
insert into t1(id, x) select row_number()over(), mod(row_number()over(), 19) from rdb$types;
46+
commit;
47+
create index t1_x on t1(x);
48+
"""
49+
db = db_factory(init = init_sql)
50+
51+
act = python_act('db')
52+
53+
def replace_leading(source, char="#"):
54+
stripped = source.lstrip()
55+
return char * (len(source) - len(stripped)) + stripped
56+
57+
@pytest.mark.version('>=5.0')
58+
def test_1(act: Action, capsys):
59+
60+
test_sql = """
61+
select a.x
62+
from t1 a
63+
where exists(
64+
select *
65+
from t1 b
66+
where b.x in (a.x, 2*a.x, 3*a.x)
67+
)
68+
"""
69+
70+
act.expected_stdout = """
71+
Sub-query
72+
####-> Filter
73+
########-> Table "T1" as "B" Access By ID
74+
############-> Bitmap
75+
################-> Index "T1_X" Full Scan
76+
Select Expression
77+
####-> Filter
78+
########-> Table "T1" as "A" Full Scan
79+
"""
80+
with act.db.connect() as con:
81+
cur = con.cursor()
82+
ps = cur.prepare(test_sql)
83+
print( '\n'.join([replace_leading(s) for s in ps.detailed_plan .split('\n')]) )
84+
85+
act.stdout = capsys.readouterr().out
86+
assert act.clean_stdout == act.clean_expected_stdout

0 commit comments

Comments
 (0)