2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
"""
|
|
|
|
ID: issue-4848
|
|
|
|
ISSUE: 4848
|
|
|
|
TITLE: DB_KEY based join of two tables may be ineffective
|
|
|
|
DESCRIPTION:
|
|
|
|
Order of expressions in the join condition could negatively affect the generated plan
|
|
|
|
and thus performance
|
|
|
|
JIRA: CORE-4530
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.core_4530
|
2022-01-23 20:41:55 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
import pytest
|
|
|
|
from firebird.qa import *
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
init_script = """
|
2021-04-26 20:07:00 +02:00
|
|
|
recreate table t (id int, constraint t_pk primary key(id) using index t_pk_idx);
|
|
|
|
commit;
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
db = db_factory(init=init_script)
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
test_script = """
|
2021-04-26 20:07:00 +02:00
|
|
|
set planonly;
|
|
|
|
|
|
|
|
-- This query had bad generated plan before fix core-4530:
|
2022-01-23 20:41:55 +01:00
|
|
|
-- PLAN JOIN (X A ORDER RDB$PRIMARY4, Z NATURAL)
|
2021-04-26 20:07:00 +02:00
|
|
|
select count(*)
|
|
|
|
from (select id, rdb$db_key k from t a order by id) x
|
|
|
|
left join t z on x.k = z.rdb$db_key; -------------------- left side: `x.k`, right side: `z.rdb$db_key`
|
|
|
|
|
|
|
|
select count(*)
|
|
|
|
from (select id, rdb$db_key k from t a order by id) x
|
|
|
|
left join t z on z.rdb$db_key = x.k; -------------------- left side: `z.rdb$db_key`, right side: `x.k`
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
act = isql_act('db', test_script)
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
expected_stdout = """
|
2021-04-26 20:07:00 +02:00
|
|
|
PLAN JOIN (X A ORDER T_PK_IDX, Z INDEX ())
|
|
|
|
PLAN JOIN (X A ORDER T_PK_IDX, Z INDEX ())
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
@pytest.mark.version('>=3.0')
|
2022-01-23 20:41:55 +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
|
|
|
|