2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
|
|
|
|
2022-01-24 20:27:02 +01:00
|
|
|
"""
|
|
|
|
ID: issue-4983
|
|
|
|
ISSUE: 4983
|
|
|
|
TITLE: Regression: computed index based on a computed column stores NULL for all its keys
|
|
|
|
DESCRIPTION:
|
|
|
|
JIRA: CORE-4673
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.core_4673
|
2022-01-24 20:27:02 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-24 20:27:02 +01:00
|
|
|
import pytest
|
|
|
|
from firebird.qa import *
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-24 20:27:02 +01:00
|
|
|
init_script = """
|
2021-04-26 20:07:00 +02:00
|
|
|
recreate table tc(
|
|
|
|
id int primary key
|
|
|
|
,x int
|
|
|
|
,y int
|
|
|
|
,z_expr computed by (x+y)
|
|
|
|
,z_noex computed by (y)
|
|
|
|
);
|
|
|
|
commit;
|
|
|
|
insert into tc values( 1, 101, 201 );
|
|
|
|
commit;
|
|
|
|
create index tc_lpad_z_expr on tc computed by( lpad('' || z_expr , 10, 0) );
|
|
|
|
|
2022-01-24 20:27:02 +01:00
|
|
|
-- Added 2nd COMPUTED_BY index WITHOUT any expression,
|
2021-04-26 20:07:00 +02:00
|
|
|
-- see dimitr's issue in the ticket, 02/Feb/15 08:52 AM.
|
2022-01-24 20:27:02 +01:00
|
|
|
-- See also several samples (rus):
|
2021-04-26 20:07:00 +02:00
|
|
|
-- sql.ru/forum/actualutils.aspx?action=gotomsg&tid=945713&msg=12655568
|
2022-01-24 20:27:02 +01:00
|
|
|
create index tc_lpad_z_noex on tc computed by( z_noex );
|
2021-04-26 20:07:00 +02:00
|
|
|
commit;
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-24 20:27:02 +01:00
|
|
|
db = db_factory(init=init_script)
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-24 20:27:02 +01:00
|
|
|
test_script = """
|
2021-04-26 20:07:00 +02:00
|
|
|
set plan on;
|
|
|
|
set list on;
|
|
|
|
select count(*) check_cnt from tc where tc.z_noex = 201
|
|
|
|
union all
|
|
|
|
select count(*) from tc where 0 + tc.z_noex = 201
|
|
|
|
union all
|
|
|
|
select count(*) cnt from tc where lpad('' || tc.z_expr, 10, 0) between '0000000302' and '0000000302'
|
|
|
|
union all
|
|
|
|
select count(*) from tc where '' || lpad('' || tc.z_expr, 10, 0) between '0000000302' and '0000000302';
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-24 20:27:02 +01:00
|
|
|
act = isql_act('db', test_script)
|
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
|
|
|
PLAN (TC INDEX (TC_LPAD_Z_NOEX), TC NATURAL, TC INDEX (TC_LPAD_Z_EXPR), TC NATURAL)
|
|
|
|
CHECK_CNT 1
|
|
|
|
CHECK_CNT 1
|
|
|
|
CHECK_CNT 1
|
|
|
|
CHECK_CNT 1
|
2021-12-22 20:23:11 +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):
|
|
|
|
act.expected_stdout = expected_stdout
|
|
|
|
act.execute()
|
|
|
|
assert act.clean_stdout == act.clean_expected_stdout
|
2021-04-26 20:07:00 +02:00
|
|
|
|