2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
|
|
|
|
2022-01-20 17:32:14 +01:00
|
|
|
"""
|
|
|
|
ID: issue-1966
|
|
|
|
ISSUE: 1966
|
|
|
|
TITLE: Subquery-based predicates are not evaluated early in the join order
|
|
|
|
DESCRIPTION:
|
|
|
|
JIRA: CORE-1549
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.core_1549
|
2022-01-20 17:32:14 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-20 17:32:14 +01:00
|
|
|
import pytest
|
|
|
|
from firebird.qa import *
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-20 17:32:14 +01:00
|
|
|
db = db_factory()
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-20 17:32:14 +01:00
|
|
|
test_script = """
|
2021-04-26 20:07:00 +02:00
|
|
|
recreate table t(id int);
|
|
|
|
commit;
|
|
|
|
insert into t select row_number()over() from rdb$types a, (select 1 i from rdb$types rows 4) b rows 1000;
|
|
|
|
commit;
|
|
|
|
create index t_id on t(id);
|
|
|
|
commit;
|
2022-01-20 17:32:14 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
-- Query-1:
|
|
|
|
set list on;
|
|
|
|
select '' as "EXISTS with ref. to 1st stream:" from rdb$database;
|
|
|
|
|
|
|
|
set planonly;
|
|
|
|
set explain on;
|
|
|
|
|
|
|
|
select a.id a_id, b.id b_id
|
|
|
|
from t a join t b on b.id >= a.id
|
|
|
|
where
|
|
|
|
not exists (select * from t x where x.id = a.id - 1)
|
|
|
|
and
|
|
|
|
not exists (select * from t z where z.id = b.id + 1);
|
|
|
|
|
|
|
|
set planonly;
|
|
|
|
set plan off;
|
|
|
|
set explain off;
|
2022-01-20 17:32:14 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
select '' as "Two sep. DT and EXISTS inside:" from rdb$database;
|
|
|
|
|
|
|
|
set planonly;
|
|
|
|
set explain on;
|
|
|
|
-- Query-2
|
|
|
|
-- (serves as "etalone" -- how it should be in query-1):
|
|
|
|
select a.id a_id, b.id b_id
|
|
|
|
from (
|
|
|
|
select t1.id
|
|
|
|
from t t1
|
|
|
|
where
|
|
|
|
not exists (select * from t x where x.id = t1.id - 1)
|
|
|
|
) a
|
|
|
|
join
|
|
|
|
(
|
|
|
|
select t2.id
|
|
|
|
from t t2
|
|
|
|
where
|
|
|
|
not exists (select * from t x where x.id = t2.id + 1)
|
|
|
|
) b
|
|
|
|
on b.id >= a.id;
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-20 17:32:14 +01:00
|
|
|
act = isql_act('db', test_script)
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2023-03-04 16:49:13 +01:00
|
|
|
fb3x_expected_out = """
|
|
|
|
EXISTS with ref. to 1st stream:
|
2022-01-20 17:32:14 +01:00
|
|
|
|
2023-03-04 16:49:13 +01:00
|
|
|
Select Expression
|
|
|
|
-> Filter
|
|
|
|
-> Table "T" as "X" Access By ID
|
|
|
|
-> Bitmap
|
|
|
|
-> Index "T_ID" Range Scan (full match)
|
|
|
|
Select Expression
|
|
|
|
-> Filter
|
|
|
|
-> Table "T" as "Z" Access By ID
|
|
|
|
-> Bitmap
|
|
|
|
-> Index "T_ID" Range Scan (full match)
|
|
|
|
Select Expression
|
|
|
|
-> Nested Loop Join (inner)
|
|
|
|
-> Filter
|
|
|
|
-> Table "T" as "A" Full Scan
|
|
|
|
-> Filter
|
|
|
|
-> Table "T" as "B" Access By ID
|
|
|
|
-> Bitmap
|
|
|
|
-> Index "T_ID" Range Scan (lower bound: 1/1)
|
|
|
|
|
|
|
|
|
|
|
|
Two sep. DT and EXISTS inside:
|
|
|
|
|
|
|
|
Select Expression
|
|
|
|
-> Filter
|
|
|
|
-> Table "T" as "B X" Access By ID
|
|
|
|
-> Bitmap
|
|
|
|
-> Index "T_ID" Range Scan (full match)
|
|
|
|
Select Expression
|
|
|
|
-> Filter
|
|
|
|
-> Table "T" as "A X" Access By ID
|
|
|
|
-> Bitmap
|
|
|
|
-> Index "T_ID" Range Scan (full match)
|
|
|
|
Select Expression
|
|
|
|
-> Nested Loop Join (inner)
|
|
|
|
-> Filter
|
|
|
|
-> Table "T" as "A T1" Full Scan
|
|
|
|
-> Filter
|
|
|
|
-> Table "T" as "B T2" Access By ID
|
|
|
|
-> Bitmap
|
|
|
|
-> Index "T_ID" Range Scan (lower bound: 1/1)
|
|
|
|
"""
|
|
|
|
|
|
|
|
fb5x_expected_out = """
|
|
|
|
EXISTS with ref. to 1st stream:
|
|
|
|
|
|
|
|
Sub-query
|
2021-04-26 20:07:00 +02:00
|
|
|
-> Filter
|
|
|
|
-> Table "T" as "X" Access By ID
|
|
|
|
-> Bitmap
|
|
|
|
-> Index "T_ID" Range Scan (full match)
|
2023-03-04 16:49:13 +01:00
|
|
|
Sub-query
|
2021-04-26 20:07:00 +02:00
|
|
|
-> Filter
|
|
|
|
-> Table "T" as "Z" Access By ID
|
|
|
|
-> Bitmap
|
|
|
|
-> Index "T_ID" Range Scan (full match)
|
|
|
|
Select Expression
|
|
|
|
-> Nested Loop Join (inner)
|
|
|
|
-> Filter
|
|
|
|
-> Table "T" as "A" Full Scan
|
|
|
|
-> Filter
|
|
|
|
-> Table "T" as "B" Access By ID
|
|
|
|
-> Bitmap
|
|
|
|
-> Index "T_ID" Range Scan (lower bound: 1/1)
|
2022-01-20 17:32:14 +01:00
|
|
|
|
2023-03-04 16:49:13 +01:00
|
|
|
Two sep. DT and EXISTS inside:
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-20 17:32:14 +01:00
|
|
|
|
2023-03-04 16:49:13 +01:00
|
|
|
|
|
|
|
Sub-query
|
2021-04-26 20:07:00 +02:00
|
|
|
-> Filter
|
|
|
|
-> Table "T" as "B X" Access By ID
|
|
|
|
-> Bitmap
|
|
|
|
-> Index "T_ID" Range Scan (full match)
|
2023-03-04 16:49:13 +01:00
|
|
|
Sub-query
|
2021-04-26 20:07:00 +02:00
|
|
|
-> Filter
|
|
|
|
-> Table "T" as "A X" Access By ID
|
|
|
|
-> Bitmap
|
|
|
|
-> Index "T_ID" Range Scan (full match)
|
|
|
|
Select Expression
|
|
|
|
-> Nested Loop Join (inner)
|
|
|
|
-> Filter
|
|
|
|
-> Table "T" as "A T1" Full Scan
|
|
|
|
-> Filter
|
|
|
|
-> Table "T" as "B T2" Access By ID
|
|
|
|
-> Bitmap
|
|
|
|
-> Index "T_ID" Range Scan (lower bound: 1/1)
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
@pytest.mark.version('>=3.0')
|
2022-01-20 17:32:14 +01:00
|
|
|
def test_1(act: Action):
|
2023-03-04 16:49:13 +01:00
|
|
|
act.expected_stdout = fb3x_expected_out if act.is_version('<5') else fb5x_expected_out
|
|
|
|
act.execute(combine_output = True)
|
2022-01-20 17:32:14 +01:00
|
|
|
assert act.clean_stdout == act.clean_expected_stdout
|
2021-04-26 20:07:00 +02:00
|
|
|
|