2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
|
|
|
#
|
|
|
|
# id: bugs.core_1389
|
|
|
|
# title: Indexed MIN/MAX aggregates produce three index reads instead of the expected one indexed read
|
2021-11-11 18:01:08 +01:00
|
|
|
# decription:
|
2021-04-26 20:07:00 +02:00
|
|
|
# We use API call db_info(fdb.isc_info_read_idx_count) for obtaining number of indexed reads and
|
|
|
|
# extract their values which are reported per table and are cumulative since start of attachment.
|
2021-11-11 18:01:08 +01:00
|
|
|
# Four statements are used for analyzing (table have all needed indexes):
|
2021-04-26 20:07:00 +02:00
|
|
|
# * select max(x) from ...;
|
2021-11-11 18:01:08 +01:00
|
|
|
# * select x from ... order by x asc rows 1;
|
2021-04-26 20:07:00 +02:00
|
|
|
# * select min(y) from ...;
|
2021-11-11 18:01:08 +01:00
|
|
|
# * select y from ... order by y desc rows 1;
|
|
|
|
#
|
2021-04-26 20:07:00 +02:00
|
|
|
# All of them must take only one indexed read.
|
2021-11-11 18:01:08 +01:00
|
|
|
#
|
2021-04-26 20:07:00 +02:00
|
|
|
# Info about 'isc_info_read_idx_count':
|
|
|
|
# Number of indexed database reads <...>
|
|
|
|
# Reported per table.
|
|
|
|
# Calculated since the current database attachment started // CUMULATIVE!
|
2021-11-11 18:01:08 +01:00
|
|
|
#
|
2021-04-26 20:07:00 +02:00
|
|
|
# See also:
|
|
|
|
# http://pythonhosted.org/fdb/reference.html#fdb.Connection.database_info
|
2021-11-11 18:01:08 +01:00
|
|
|
#
|
2021-04-26 20:07:00 +02:00
|
|
|
# Confirmed bug on WI-V2.0.0.12724: db_info() received 3 (three) indexed reads instead of 1 for queries:
|
|
|
|
# 'select min(...) from ...' and 'select max(...) from ...'
|
2021-11-11 18:01:08 +01:00
|
|
|
#
|
2021-04-26 20:07:00 +02:00
|
|
|
# tracker_id: CORE-1389
|
|
|
|
# min_versions: ['2.5.0']
|
|
|
|
# versions: 2.5
|
|
|
|
# qmid: None
|
|
|
|
|
|
|
|
import pytest
|
2021-11-11 18:01:08 +01:00
|
|
|
from firebird.qa import db_factory, python_act, Action
|
|
|
|
from firebird.driver import DbInfoCode
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
# version: 2.5
|
|
|
|
# resources: None
|
|
|
|
|
|
|
|
substitutions_1 = []
|
|
|
|
|
|
|
|
init_script_1 = """
|
|
|
|
recreate table test(x int, y int);
|
|
|
|
commit;
|
|
|
|
insert into test(x, y)
|
|
|
|
select -1, 1 from (select 1 i from rdb$types rows 200) a, (select 1 i from rdb$types rows 200) b;
|
|
|
|
commit;
|
|
|
|
|
|
|
|
create index test_x on test(x);
|
|
|
|
create descending index test_y on test(y);
|
|
|
|
commit;
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
db_1 = db_factory(sql_dialect=3, init=init_script_1)
|
|
|
|
|
|
|
|
# test_script_1
|
|
|
|
#---
|
|
|
|
# import fdb
|
|
|
|
# sql_get_rel_id="select rdb$relation_id from rdb$relations where trim(rdb$relation_name)=upper('test')"
|
2021-11-11 18:01:08 +01:00
|
|
|
#
|
2021-04-26 20:07:00 +02:00
|
|
|
# cur=db_conn.cursor()
|
|
|
|
# cur.execute(sql_get_rel_id)
|
2021-11-11 18:01:08 +01:00
|
|
|
#
|
2021-04-26 20:07:00 +02:00
|
|
|
# test_rel=-1
|
|
|
|
# for r in cur:
|
|
|
|
# test_rel=r[0]
|
2021-11-11 18:01:08 +01:00
|
|
|
#
|
|
|
|
# sql_set=[
|
|
|
|
# 'select min(x) from test',
|
2021-04-26 20:07:00 +02:00
|
|
|
# 'select x from test order by x rows 1',
|
2021-11-11 18:01:08 +01:00
|
|
|
# 'select max(y) from test',
|
|
|
|
# 'select y from test order by y desc rows 1'
|
2021-04-26 20:07:00 +02:00
|
|
|
# ]
|
2021-11-11 18:01:08 +01:00
|
|
|
#
|
2021-04-26 20:07:00 +02:00
|
|
|
# v_previous_idx_counter=0
|
|
|
|
# for i in range(0,len(sql_set)):
|
|
|
|
# cur.execute(sql_set[i])
|
|
|
|
# for r in cur:
|
|
|
|
# y=r[0]
|
2021-11-11 18:01:08 +01:00
|
|
|
#
|
2021-04-26 20:07:00 +02:00
|
|
|
# info = db_conn.db_info(fdb.isc_info_read_idx_count)
|
|
|
|
# # WI-V2.0.0.12724
|
|
|
|
# for k,v_cumulative_idx_counter in info.items():
|
|
|
|
# if k == test_rel:
|
|
|
|
# print( 'Number of indexed reads: ' + str(v_cumulative_idx_counter - v_previous_idx_counter) )
|
|
|
|
# v_previous_idx_counter = v_cumulative_idx_counter
|
|
|
|
# cur.close()
|
2021-11-11 18:01:08 +01:00
|
|
|
#
|
2021-04-26 20:07:00 +02:00
|
|
|
#---
|
|
|
|
|
2021-11-11 18:01:08 +01:00
|
|
|
act_1 = python_act('db_1', substitutions=substitutions_1)
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2021-11-11 18:01:08 +01:00
|
|
|
expected_stdout_1 = """Number of indexed reads: 1
|
|
|
|
Number of indexed reads: 1
|
|
|
|
Number of indexed reads: 1
|
|
|
|
Number of indexed reads: 1
|
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2021-11-11 18:01:08 +01:00
|
|
|
@pytest.mark.version('>=2.5')
|
|
|
|
def test_1(act_1: Action, capsys):
|
|
|
|
with act_1.db.connect() as con:
|
|
|
|
c = con.cursor()
|
|
|
|
c.execute("select rdb$relation_id from rdb$relations where trim(rdb$relation_name)=upper('test')")
|
|
|
|
test_rel = c.fetchone()[0]
|
|
|
|
#
|
|
|
|
sql_set=['select min(x) from test',
|
|
|
|
'select x from test order by x rows 1',
|
|
|
|
'select max(y) from test',
|
|
|
|
'select y from test order by y desc rows 1']
|
|
|
|
previous_idx_counter = 0
|
|
|
|
for cmd in sql_set:
|
|
|
|
c.execute(cmd).fetchone()
|
|
|
|
counts = con.info.get_info(DbInfoCode.READ_IDX_COUNT)
|
|
|
|
for k, cumulative_idx_counter in counts.items():
|
|
|
|
if k == test_rel:
|
|
|
|
print('Number of indexed reads:', cumulative_idx_counter - previous_idx_counter)
|
|
|
|
previous_idx_counter = cumulative_idx_counter
|
|
|
|
#
|
|
|
|
output = capsys.readouterr()
|
|
|
|
assert output.out == expected_stdout_1
|