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_selectivity_03.py

118 lines
2.9 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.selectivity-03
TITLE: SELECTIVITY - INDEX INACTIVE / ACTIVE
DESCRIPTION:
Check if selectivity is calculated correctly.
2022-02-04 19:05:19 +01:00
FBTEST: functional.arno.optimizer.opt_selectivity_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 SelectivityTest (
2021-04-26 20:07:00 +02:00
F1 INTEGER NOT NULL,
F2 INTEGER,
F5 INTEGER,
F50 INTEGER
);
SET TERM ^^ ;
CREATE PROCEDURE PR_SelectivityTest
AS
DECLARE VARIABLE FillID INTEGER;
BEGIN
FillID = 1;
WHILE (FillID <= 1000) DO
BEGIN
INSERT INTO SelectivityTest
(F1, F2, F5, F50)
VALUES
(:FillID,
(:FILLID / 2) * 2,
(:FILLID / 5) * 5,
(:FILLID / 50) * 50);
FillID = FillID + 1;
END
END
^^
SET TERM ; ^^
COMMIT;
/* Create indexes */
CREATE UNIQUE ASC INDEX I_F01_ASC ON SelectivityTest (F1);
CREATE UNIQUE DESC INDEX I_F01_DESC ON SelectivityTest (F1);
CREATE ASC INDEX I_F02_ASC ON SelectivityTest (F2);
CREATE DESC INDEX I_F02_DESC ON SelectivityTest (F2);
CREATE ASC INDEX I_F05_ASC ON SelectivityTest (F5);
CREATE DESC INDEX I_F05_DESC ON SelectivityTest (F5);
CREATE ASC INDEX I_F50_ASC ON SelectivityTest (F50);
CREATE DESC INDEX I_F50_DESC ON SelectivityTest (F50);
COMMIT;
/* Deactivate indexes */
ALTER INDEX I_F01_ASC INACTIVE;
ALTER INDEX I_F01_DESC INACTIVE;
ALTER INDEX I_F02_ASC INACTIVE;
ALTER INDEX I_F02_DESC INACTIVE;
ALTER INDEX I_F05_ASC INACTIVE;
ALTER INDEX I_F05_DESC INACTIVE;
ALTER INDEX I_F50_ASC INACTIVE;
ALTER INDEX I_F50_DESC INACTIVE;
COMMIT;
/* Fill table with data */
EXECUTE PROCEDURE PR_SelectivityTest;
COMMIT;
/* Activate indexes */
ALTER INDEX I_F01_ASC ACTIVE;
ALTER INDEX I_F01_DESC ACTIVE;
ALTER INDEX I_F02_ASC ACTIVE;
ALTER INDEX I_F02_DESC ACTIVE;
ALTER INDEX I_F05_ASC ACTIVE;
ALTER INDEX I_F05_DESC ACTIVE;
ALTER INDEX I_F50_ASC ACTIVE;
ALTER INDEX I_F50_DESC ACTIVE;
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 OFF;
2021-04-26 20:07:00 +02:00
SELECT
CAST(RDB$INDEX_NAME AS CHAR(31)) AS INDEX_NAME,
CAST(RDB$STATISTICS AS NUMERIC(18,5)) AS SELECTIVITY
FROM
RDB$INDICES
WHERE
RDB$RELATION_NAME = 'SELECTIVITYTEST'
ORDER BY
RDB$INDEX_NAME;"""
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 = """INDEX_NAME SELECTIVITY
2021-04-26 20:07:00 +02:00
=============================== =====================
I_F01_ASC 0.00100
I_F01_DESC 0.00100
I_F02_ASC 0.00200
I_F02_DESC 0.00200
I_F05_ASC 0.00498
I_F05_DESC 0.00498
I_F50_ASC 0.04762
I_F50_DESC 0.04762"""
2021-04-26 20:07:00 +02:00
2022-01-28 18:56:36 +01:00
@pytest.mark.version('>=3')
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute()
assert act.clean_stdout == act.clean_expected_stdout