6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-23 05:53:06 +01:00
firebird-qa/tests/functional/arno/optimizer/test_opt_mixed_joins_03.py

111 lines
2.1 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-28 18:56:36 +01:00
"""
ID: optimizer.mixed-joins-03
TITLE: Mixed JOINS
DESCRIPTION:
Tables without indexes should be merged (when inner join) and those who can use a index, should use it.
2022-02-04 19:05:19 +01:00
FBTEST: functional.arno.optimizer.opt_mixed_joins_03
2022-01-28 18:56:36 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-28 18:56:36 +01:00
import pytest
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-28 18:56:36 +01:00
init_script = """CREATE TABLE Table_1 (
2021-04-26 20:07:00 +02:00
ID INTEGER NOT NULL
);
CREATE TABLE Table_10 (
ID INTEGER NOT NULL
);
CREATE TABLE Table_100 (
ID INTEGER NOT NULL
);
CREATE TABLE Table_1000 (
ID INTEGER NOT NULL
);
SET TERM ^^ ;
CREATE PROCEDURE PR_FillTable_10
AS
DECLARE VARIABLE FillID INTEGER;
BEGIN
FillID = 1;
WHILE (FillID <= 10) DO
BEGIN
INSERT INTO Table_10 (ID) VALUES (:FillID);
FillID = FillID + 1;
END
END
^^
CREATE PROCEDURE PR_FillTable_100
AS
DECLARE VARIABLE FillID INTEGER;
BEGIN
FillID = 1;
WHILE (FillID <= 100) DO
BEGIN
INSERT INTO Table_100 (ID) VALUES (:FillID);
FillID = FillID + 1;
END
END
^^
CREATE PROCEDURE PR_FillTable_1000
AS
DECLARE VARIABLE FillID INTEGER;
BEGIN
FillID = 1;
WHILE (FillID <= 1000) DO
BEGIN
INSERT INTO Table_1000 (ID) VALUES (:FillID);
FillID = FillID + 1;
END
END
^^
SET TERM ; ^^
COMMIT;
INSERT INTO Table_1 (ID) VALUES (1);
EXECUTE PROCEDURE PR_FillTable_10;
EXECUTE PROCEDURE PR_FillTable_100;
EXECUTE PROCEDURE PR_FillTable_1000;
COMMIT;
CREATE UNIQUE ASC INDEX PK_Table_1 ON Table_1 (ID);
CREATE UNIQUE ASC INDEX PK_Table_100 ON Table_100 (ID);
COMMIT;
"""
2022-01-28 18:56:36 +01:00
db = db_factory(init=init_script)
2021-04-26 20:07:00 +02:00
2022-01-28 18:56:36 +01:00
test_script = """SET PLAN ON;
2021-04-26 20:07:00 +02:00
SELECT
Count(*)
FROM
Table_10 t10
LEFT JOIN Table_1 t1 ON (t1.ID = t10.ID)
JOIN Table_1000 t1000 ON (t1000.ID = t10.ID)
JOIN Table_100 t100 ON (t100.ID = t1000.ID);"""
2021-04-26 20:07:00 +02:00
2022-01-28 18:56:36 +01:00
act = isql_act('db', test_script)
2021-04-26 20:07:00 +02:00
2022-01-28 18:56:36 +01:00
expected_stdout = """PLAN HASH (T1000 NATURAL, JOIN (JOIN (T10 NATURAL, T1 INDEX (PK_TABLE_1)), T100 INDEX (PK_TABLE_100)))
2021-04-26 20:07:00 +02:00
COUNT
=====================
10
"""
@pytest.mark.version('>=3.0')
2022-01-28 18:56:36 +01:00
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute()
assert act.clean_stdout == act.clean_expected_stdout