#coding:utf-8 # # id: bugs.core_1361 # title: Index operations for global temporary tables are not visible for the active connection # decription: # Checked on: # 4.0.0.1635 SS: 1.863s. # 4.0.0.1633 CS: 2.386s. # 3.0.5.33180 SS: 1.302s. # 3.0.5.33178 CS: 1.778s. # # tracker_id: # min_versions: ['3.0'] # versions: 3.0 # qmid: bugs.core_1361 import pytest from firebird.qa import db_factory, isql_act, Action # version: 3.0 # resources: None substitutions_1 = [] init_script_1 = """ set term ^; create or alter procedure sp_check_plan returns(sql_plan blob) as begin end ^ execute block as begin begin execute statement 'drop role poor_dba'; when any do begin end end begin execute statement 'drop role cool_dba'; when any do begin end end begin execute statement 'drop role super_dba'; when any do begin end end end ^ set term ;^ commit; recreate global temporary table gtt_session(x int, y int) on commit preserve rows; commit; create role poor_dba; create role cool_dba; create role super_dba; commit; grant poor_dba to sysdba; -- for connect #1 grant cool_dba to sysdba; -- for connect #2 grant super_dba to sysdba; -- for connect #3 (index also WILL be seen for it) commit; set term ^; create or alter procedure sp_check_plan returns(sql_plan blob) as declare n int; begin insert into gtt_session select rand()*100, rand()*100 from rdb$types,rdb$triggers union all select -2, -3 from rdb$database; execute statement 'select ' || ' (select count(*) from gtt_session g where g.x + g.y = -5) ' || ' ,mon$explained_plan ' || 'from mon$statements s ' || 'where s.mon$transaction_id = current_transaction and mon$explained_plan containing ''GTT_SESSION'' ' || 'rows 1' into n, sql_plan; suspend; end ^ set term ;^ commit; """ db_1 = db_factory(sql_dialect=3, init=init_script_1) test_script_1 = """ set list on; set blob all; set term ^; execute block returns(using_index smallint) as declare v_dbname type of column mon$database.mon$database_name; declare v_usr varchar(31) = 'SYSDBA'; declare v_pwd varchar(20) = 'masterkey'; declare role_1 varchar(31) = 'POOR_DBA'; declare role_2 varchar(31) = 'COOL_DBA'; declare role_3 varchar(31) = 'SUPER_DBA'; declare sql_plan blob; begin v_dbname = 'localhost:' || rdb$get_context('SYSTEM', 'DB_NAME'); execute statement 'select sql_plan from sp_check_plan' on external v_dbname as user v_usr password v_pwd role upper( role_1 ) into sql_plan; using_index = iif(sql_plan containing 'GTT_SESSION_X_Y', 1, 0); suspend; -------------------------------------------------------- execute statement 'create index gtt_session_x_y on gtt_session computed by ( x+y )' with autonomous transaction on external v_dbname as user v_usr password v_pwd role upper( role_2 ); -- nb: changing this to 'role_1' will produce in firebird.log: -- internal Firebird consistency check (invalid SEND request (167), -- file: JrdStatement.cpp line: 325) execute statement 'select sql_plan from sp_check_plan' on external v_dbname as user v_usr password v_pwd role upper( role_2 ) into sql_plan; using_index = iif(sql_plan containing 'GTT_SESSION_X_Y', 1, 0); suspend; -------------------------------------------------------- execute statement 'select sql_plan from sp_check_plan' on external v_dbname as user v_usr password v_pwd role upper( role_3 ) into sql_plan; using_index = iif(sql_plan containing 'GTT_SESSION_X_Y', 1, 0); suspend; end ^ set term ;^ commit; -- |||||||||||||||||||||||||||| -- ###################################||| FB 4.0+, SS and SC |||############################## -- |||||||||||||||||||||||||||| -- If we check SS or SC and ExtConnPoolLifeTime > 0 (config parameter FB 4.0+) then current -- DB (bugs.core_NNNN.fdb) will be 'captured' by firebird.exe process and fbt_run utility -- will not able to drop this database at the final point of test. -- Moreover, DB file will be hold until all activity in firebird.exe completed and AFTER this -- we have to wait for seconds after it (discussion and small test see -- in the letter to hvlad and dimitr 13.10.2019 11:10). -- This means that one need to kill all connections to prevent from exception on cleanup phase: -- SQLCODE: -901 / lock time-out on wait transaction / object is in use -- ############################################################################################# delete from mon$attachments where mon$attachment_id != current_connection; commit; """ act_1 = isql_act('db_1', test_script_1, substitutions=substitutions_1) expected_stdout_1 = """ USING_INDEX 0 USING_INDEX 1 USING_INDEX 1 """ @pytest.mark.version('>=3.0') def test_1(act_1: Action): act_1.expected_stdout = expected_stdout_1 act_1.execute() assert act_1.clean_expected_stdout == act_1.clean_stdout