2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
|
|
|
|
2022-01-24 20:27:02 +01:00
|
|
|
"""
|
|
|
|
ID: issue-5010
|
|
|
|
ISSUE: 5010
|
|
|
|
TITLE: Regression: Join order in v3 is less optimal than in v2.x
|
|
|
|
DESCRIPTION:
|
|
|
|
JIRA: CORE-4702
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.core_4702
|
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 trial_line (
|
|
|
|
code_trial_line integer not null,
|
|
|
|
code_trial integer not null
|
|
|
|
);
|
2022-01-24 20:27:02 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
recreate table trial (
|
|
|
|
code_trial integer not null,
|
|
|
|
code_prize integer not null,
|
|
|
|
bydate date
|
|
|
|
);
|
2022-01-24 20:27:02 +01:00
|
|
|
|
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
recreate table prize (
|
|
|
|
code_prize integer not null,
|
|
|
|
name varchar(70) not null
|
|
|
|
);
|
|
|
|
commit;
|
2022-01-24 20:27:02 +01:00
|
|
|
|
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
insert into prize(code_prize, name)
|
|
|
|
with recursive t (n) as (
|
|
|
|
select 1 from rdb$database
|
|
|
|
union all
|
|
|
|
select n+1 from t where n < 1000
|
|
|
|
)
|
|
|
|
select n+8000, '' from t;
|
|
|
|
commit;
|
2022-01-24 20:27:02 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
insert into trial(code_trial, code_prize, bydate)
|
|
|
|
with recursive t (n) as (
|
|
|
|
select 1 from rdb$database
|
|
|
|
union all
|
|
|
|
select n+1 from t where n < 1000
|
|
|
|
)
|
|
|
|
select t1.n + (t2.n-1)*1000, mod(t1.n, 20)+8001, dateadd(t1.n day to date '01.01.2000')
|
|
|
|
from t t1, t t2
|
|
|
|
where t1.n + (t2.n-1)*1000 < 100000;
|
|
|
|
commit;
|
2022-01-24 20:27:02 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
insert into trial_line(code_trial_line, code_trial)
|
|
|
|
with recursive t (n) as (
|
|
|
|
select 1 from rdb$database
|
|
|
|
union all
|
|
|
|
select n+1 from t where n < 1000
|
|
|
|
)
|
|
|
|
select t1.n + (t2.n-1)*1000, mod(t1.n + (t2.n-1)*1000, 99998)+1
|
|
|
|
from t t1, t t2
|
|
|
|
where t1.n + (t2.n-1)*1000 < 150000;
|
|
|
|
commit;
|
2022-01-24 20:27:02 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
alter table trial add constraint pk_trial primary key (code_trial);
|
|
|
|
alter table prize add constraint pk_prize primary key (code_prize);
|
|
|
|
alter table trial_line add constraint pk_trial_line primary key (code_trial_line);
|
2022-01-24 20:27:02 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
alter table trial_line add constraint fk_trial_line_trial foreign key (code_trial) references trial (code_trial);
|
|
|
|
alter table trial add constraint fk_trial_prize foreign key (code_prize) references prize (code_prize);
|
2022-01-24 20:27:02 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
create index idx_bydate on trial(bydate);
|
|
|
|
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 planonly;
|
|
|
|
select count(*)
|
|
|
|
from
|
|
|
|
trial
|
|
|
|
join prize on prize.code_prize = trial.code_prize
|
|
|
|
join trial_line on trial_line.code_trial = trial.code_trial
|
2022-01-24 20:27:02 +01:00
|
|
|
where trial.bydate between date '01.01.2000' and date '31.12.2000';
|
2021-04-26 20:07:00 +02:00
|
|
|
-- Confirmed ineffective plan in WI-T3.0.0.31374 Firebird 3.0 Beta 1:
|
|
|
|
-- PLAN JOIN (TRIAL INDEX (IDX_BYDATE), TRIAL_LINE INDEX (FK_TRIAL_LINE_TRIAL), PRIZE INDEX (PK_PRIZE))
|
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 JOIN (TRIAL INDEX (IDX_BYDATE), PRIZE INDEX (PK_PRIZE), TRIAL_LINE INDEX (FK_TRIAL_LINE_TRIAL))
|
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
|
|
|
|