config root man

Current Path : /home/usr.opt/mysql57/mysql-test/t/

FreeBSD hs32.drive.ne.jp 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Wed Jan 14 12:18:08 JST 2015 root@hs32.drive.ne.jp:/sys/amd64/compile/hs32 amd64
Upload File :
Current File : /home/usr.opt/mysql57/mysql-test/t/session_tracker_trx_state.test

# We do not support --embedded-server at this point; see WL#7766.
--source include/not_embedded.inc
--source include/have_query_cache.inc

--echo #
--echo # WL#6631: Detect transaction boundaries
--echo #

###############################################################################
# The main functionality implemented by WL#6631 is enhanced reporting
# on transaction state. Historically, the server has already reported
# with a flag whether we're inside a transaction, but on one hand,
# BEGIN..COMMIT AND CHAIN..COMMIT AND CHAIN..COMMIT AND RELEASE would
# look like a single very long transaction to users of that flag; on
# the other, we could still re-locate the session elsewhere (e.g. load-
# balance it) as long as no actual reads or writes have been done.
# A client subscribing to WL#6631 reporting will see this more granular
# state (implicit transaction, explicit transaction, work attached, etc.).
# it may additionally subscribe to reporting on the characteristics of
# the transaction (READ ONLY/READ WRITE; WITH CONSISTENT SNAPSHOT;
# ISOLATION LEVEL) so it may restart the transaction elsewhere with the
# same characteristics as the original transaction.
#
# We can switch a connection:
#
# a) if no transaction is active
#
# b) if a  transaction is active, but has no "work" attached to it yet,
#    in which case we'll want to know its characteristics to move it:
#
#    - was START TRANSACTION "WITH CONSISTENT SNAPSHOT" used?
#
#    - was START TRANSACTION used with "READ ONLY" or "READ WRITE"?
#      (if neither was given in the statement, we won't flag either,
#      so the default will be used -- it's up to the client to
#      replicate that setting from SET TRANSACTION (i.e. GLOBAL and
#      SESSION tx_isolation / tx_read_only) as needed!
#
#    - was "SET TRANSACTION ISOLATION LEVEL" one-shot set for this
#      transaction?
#
#    - was "SET TRANSACTION READ [WRITE|ONLY]" one-shot used?
#
#
# A transaction may be "explicit" (started with BEGIN WORK /
# START TRANSACTION) or "implicit" (autocommit==0 && not in an
# explicit transaction). A transaction of either type will end
# when a statement causes an implicit or explicit commit.
# In both cases, we'll see the union of any reads or writes
# (transactional and non-transactional) that happened up to
# that point in the transaction.
#
# In this test, we will document various state transitions between
# no transaction, implicit transaction, and explict transaction active.
# We will also show that "work attached" (read/write, transactional/
# non-transactional) as flagged as expected when a transaction is active.
# Next, we will show that CHARACTERISTICS tracking supplies the correct
# SQL statement or sequence of SQL statements to start a new transaction
# with characteristics identital to that of the on-going transaction.
# Finally, we'll explore some interesting situations -- reads within
# a stored function, within LOCK, etc.



--echo ########################################################################
--echo #
--echo # set up: save settings
--echo #

SET autocommit=1;
--echo # if we track CHARACTERISTICS, we must also track the tx_* sysvars!
SELECT @@session.session_track_system_variables INTO @old_track_list;
SET @track_list= CONCAT(@old_track_list,
                        ",transaction_read_only,transaction_isolation ");
SET SESSION session_track_system_variables=@track_list;

SELECT @@session.session_track_state_change INTO @old_track_enable;
SET SESSION session_track_state_change=TRUE;

SELECT @@session.session_track_transaction_info INTO @old_track_tx;

# Do not use query cache at this point; we'll enable it later when we
# test the interaction of query cache and transaction tracking.
SET SESSION query_cache_type = 0;
FLUSH STATUS;



--echo ########################################################################
--echo #
--echo # test "STATE" tracking: transaction type transitions
--echo #

SET SESSION session_track_transaction_info="STATE";

--enable_session_track_info

--echo # 3.1.1.1.1  "explicit transaction active"
# transition: no trx -> explicit trx
START TRANSACTION;
--echo # 3.1.1.1.1  ending explicit transaction explicitly
# transition: explicit trx -> no trx
COMMIT;
--echo # 3.1.1.1.1  ending explicit transaction implicitly
CREATE TABLE t1 (f1 INT) ENGINE="InnoDB";
START TRANSACTION;
# DDL forcing an implicit commit (thereby ending the explicit transaction):
# transition: explicit trx -> no trx
DROP TABLE t1;


--echo # 3.1.1.2    "no work attached"
# no work attached after transaction started (unless WITH CONSISTENT SNAPSHOT)
START TRANSACTION;
# still no work attached as we do not access tables, and still in transaction:
SET @dummy=0;
ROLLBACK;


--echo # 3.1.1.1.2  "implicit transaction active"
--echo #
# autocommit=0 enables implicit transactions
# transition: no trx -> implicit trx
SET autocommit=0;
# DDL forcing an implicit commit
# transition: implicit trx -> no trx
CREATE TABLE t1 (f1 INT) ENGINE="InnoDB";
# attach a (transactional, since t1 is an InnoDB table) write:
# transition: no trx -> implicit trx (with work)
INSERT INTO t1 VALUES (1);
# attach a transaction read; show that we get the union of the accesses so far:
SELECT f1 FROM t1 LIMIT 1 INTO @dummy;
# add a result-set:
SELECT f1 FROM t1;
# force commit by starting an explict transaction:
# transition: implicit trx -> explicit trx
BEGIN WORK;
# end transaction by forcing an implicit commit:
# transition: explicit trx -> no trx
DROP TABLE t1;
# start an implicit transaction
SELECT RAND(22) INTO @dummy;
# implicit transaction, explicit commit:
# transition: implicit trx -> no trx
COMMIT;
#
# SET TRANSACTION is OK during implicit transaction UNTIL tables are accessed
CREATE TABLE t1 (f1 INT) ENGINE="InnoDB";
SET TRANSACTION READ ONLY;
SET TRANSACTION READ WRITE;
SELECT RAND(22) INTO @dummy;
SET TRANSACTION READ WRITE;
INSERT INTO t1 VALUES (1);
--error ER_CANT_CHANGE_TX_CHARACTERISTICS
SET TRANSACTION READ WRITE;
DROP TABLE t1;

# change back to autocommit mode.
# Axiom: This should reset state as the implicit transaction, if any, ends.
# transition: implicit trx -> no trx
SET autocommit=1;



--echo ########################################################################
--echo #
--echo # test "STATE" tracking: transaction state reporting
--echo #

CREATE TABLE t1 (f1 INT) ENGINE="InnoDB";
CREATE TABLE t2 (f1 INT) ENGINE="MyISAM";

--echo # We don't report when in autocommit mode and outside a transaction:
INSERT INTO t1 VALUES(1);
SELECT 1 FROM DUAL;
DELETE FROM t1;



# Now start a transaction so we can actually report things!
START TRANSACTION;
--echo # add "unsafe stmt" to the set:
SET @x=UUID();
--echo # next stmt is safe, but unsafe flag should stick:
SET @x=1;
--echo # however, after C/A/C, the status should revert to "empty trx":
COMMIT AND CHAIN;
--echo # SELECT with no tables gives us just a result set
SELECT 1 FROM DUAL;
COMMIT AND CHAIN;
--echo # SELECT with no tables and no result set
--replace_result $MYSQLTEST_VARDIR VARDIR
eval SELECT 1 FROM DUAL INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/wl6631.csv';
--remove_file $MYSQLTEST_VARDIR/tmp/wl6631.csv
COMMIT AND CHAIN;
--echo # SELECT with trx tables but no result set
--replace_result $MYSQLTEST_VARDIR VARDIR
--eval SELECT f1 FROM t1 INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/wl6631.csv';
--remove_file $MYSQLTEST_VARDIR/tmp/wl6631.csv
COMMIT AND CHAIN;
--echo # SELECT with non-trx tables but no result set
--replace_result $MYSQLTEST_VARDIR VARDIR
--eval SELECT f1 FROM t2 INTO OUTFILE '$MYSQLTEST_VARDIR/tmp/wl6631.csv';
--remove_file $MYSQLTEST_VARDIR/tmp/wl6631.csv
--echo # show that "unsafe read" sticks (isn't cleared by the dummy SELECT)
SELECT 1 FROM DUAL INTO @x;
--echo # clear state
COMMIT;

DROP TABLE t1;
DROP TABLE t2;
--echo



--echo # read with and without result set:
CREATE TABLE t1 (f1 INT) ENGINE="InnoDB";
CREATE TABLE t2 (f1 INT) ENGINE="InnoDB";
INSERT INTO  t1 VALUES (123);

BEGIN;
# read + result set
SELECT f1 FROM t1;
COMMIT AND CHAIN;
# read + write
INSERT INTO t2 SELECT f1 FROM t1;
COMMIT;

DROP TABLE t1;
DROP TABLE t2;
--echo



--echo # states: read + write; transactional + non-transactional
--echo # state should be "no transaction":
CREATE TABLE t1 (f1 INT) ENGINE="InnoDB";
CREATE TABLE t2 (f1 INT) ENGINE="MyISAM";
--echo # resulting state should be "T", transaction started, no data modified:
START TRANSACTION;
--echo # resulting state should be "W", transactional write pending:
INSERT INTO t1 VALUES (1);
--echo # resulting state should be "wW", both safe and unsafe writes happened:
INSERT INTO t2 VALUES (1);
--echo # resulting state should STILL be "wW"!
INSERT INTO t1 VALUES (1);
ROLLBACK;

START TRANSACTION;
--echo # resulting state should be "w", unsafe non-transaction write happened:
INSERT INTO t2 VALUES (1);
--echo # resulting state should be "wW", both safe and unsafe writes happened:
INSERT INTO t1 VALUES (1);
--echo # resulting state should be  "RwW" (adding transactional read):
SELECT f1 FROM t1;
--echo # resulting state should be "rRwW" (adding non-transactional read):
SELECT f1 FROM t2;
# ROLLBACK will throw "couldn't roll back some tables" here.
# Prevent an implicit, hidden "SHOW WARNINGS" here that would
# lead to an extra result set, and thereby to a hidden state edge
# (and a seemingly nonsensical logged change from TX_EMPTY to TX_EMPTY).
--disable_warnings
ROLLBACK;
--enable_warnings
DROP TABLE t1, t2;
--echo



--echo # autocommit (0)
CREATE TABLE t1 (f1 INT) ENGINE="InnoDB";
SET autocommit=0;
# unsafe stmt
SET @x=UUID();
SET @x=1;
SET @x=UUID();
--echo # SET TRANSACTION one-shot should generate a tracker item when
--echo # tracking statements. Transaction state however should not change.
--echo # We can still set chistics here because in_active_multi_stmt_transaction()
--echo # is still false (!SERVER_STATUS_IN_TRANS).
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
INSERT INTO t1 VALUES(1);
--echo # Now that we've involved tables in the implicit transaction, we're
--echo # no longer allowed to change its chistics:
--error ER_CANT_CHANGE_TX_CHARACTERISTICS
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
# implicit commit (because of DROP TABLE)
BEGIN;
INSERT INTO t1 VALUES(3);
DROP TABLE t1;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
BEGIN;
SELECT 1 FROM DUAL;
SELECT 1 FROM DUAL INTO @dummy;
COMMIT;

CREATE TABLE t2 (f1 INT) ENGINE="MyISAM";
SELECT f1 FROM t2;
DROP TABLE t2;
SET autocommit=1;
--echo



--echo ########################################################################
--echo #
--echo # test "CHARACTERISTICS" tracking
--echo #

SET SESSION session_track_transaction_info="CHARACTERISTICS";
# side-effect: state will change to "explicit transaction active"
START TRANSACTION;
# side-effect: state -> "explicit transaction active" + "transactional read"
START TRANSACTION WITH CONSISTENT SNAPSHOT;
# side-effect: state -> "explicit transaction active"
START TRANSACTION READ WRITE;
--echo # state is again "we have an empty transaction", so make no state item
START TRANSACTION READ ONLY;
START TRANSACTION READ WRITE, WITH CONSISTENT SNAPSHOT;
START TRANSACTION READ ONLY,  WITH CONSISTENT SNAPSHOT;
--echo # chain read chistics, but not snapshot:
COMMIT AND CHAIN;

# We can't set characteristics one-shots with an explicit transaction ongoing:
--error ER_CANT_CHANGE_TX_CHARACTERISTICS
SET TRANSACTION   READ ONLY;

--echo # will create an empty characteristics item by convention, plus 0 state
ROLLBACK;
--echo


# Let's try the characteristics one-shots again, outside a transaction:
--echo # chistics: READ ONLY
SET TRANSACTION   READ ONLY;
--echo # chistics: READ ONLY + ISOL RR
SET TRANSACTION              ISOLATION LEVEL REPEATABLE READ;
--echo # chistics: READ ONLY + ISOL RR
SET TRANSACTION   READ ONLY;
--echo # chistics: READ WRITE + ISOL RR
SET TRANSACTION   READ WRITE;
--echo # chistics: READ WRITE + ISOL RR
SET TRANSACTION              ISOLATION LEVEL REPEATABLE READ;
--echo # chistics: READ ONLY + ISOL SER
SET TRANSACTION   READ ONLY, ISOLATION LEVEL SERIALIZABLE;
--echo # chistics: READ ONLY + ISOL SER
BEGIN WORK;
COMMIT;
--echo



# Show how the characteristics one-shots interact with the session values:

SET SESSION tx_read_only=0;
--echo # one-shot (different from session default)
SET TRANSACTION READ ONLY;
START TRANSACTION;
COMMIT;
--echo

--echo # one-shot (repeats session default)
SET TRANSACTION READ WRITE;
START TRANSACTION;
COMMIT;
--echo

--echo # session
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
--echo # "isolation" one-shot is set, and added to chistics tracker (=> 1 item)
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
--echo # "read-only" one-shot is set, and added to chistics tracker (=> 2 items)
SET TRANSACTION READ ONLY;
--echo # setting the session default:
--echo # - we receive "changed variable" for @@session.tx_read_only
--echo # - "read-only" one-shot is cleared, disappears from chistics tracker
--echo # - "isolation" one-shot remains set, and remains in chistics tracker
SET SESSION TRANSACTION READ ONLY;
--echo # chistics: isolation level is READ COMMITTED (from one-shot), READ ONLY
--echo #           or READ WRITE not given, as we're using session default again
START TRANSACTION;
COMMIT;
--echo

--echo # chistics: READ ONLY
SET TRANSACTION READ ONLY;
--echo # chistics: READ ONLY, READ COMM
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
--echo # chistics: SESSION resets ISOL one-shot,  READ ONLY remains
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
--echo # chistics: SESSION resets READ one-shot, nothing remains
SET SESSION TRANSACTION READ ONLY;
--echo

SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
SET SESSION TRANSACTION READ WRITE;

--echo



--echo # show that START TRANSACTION READ ... overrides SET TRANSACTION READ ..
SET TRANSACTION READ ONLY;
START TRANSACTION READ WRITE;
ROLLBACK;
--echo



--echo # chistics AND CHAIN
# At this point, (COMMIT as well as ROLLBACK) AND CHAIN preserves chistics:
SET TRANSACTION READ ONLY;
START TRANSACTION;
COMMIT AND CHAIN;
ROLLBACK;
--echo

SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
START TRANSACTION READ ONLY;
ROLLBACK AND CHAIN;
COMMIT;
--echo


--echo # show that session_track_transaction_info="STATE" will hide some edges
SET session_track_transaction_info="STATE";
--echo # normal syntax: TR->T->0
START TRANSACTION WITH CONSISTENT SNAPSHOT;
COMMIT AND CHAIN;
COMMIT;
--echo # normal syntax: T->T->0
START TRANSACTION;
--echo # state does not change, and therefore isn't reported
COMMIT AND CHAIN;
COMMIT;
--echo # pathological syntax: TR->TR->0
START TRANSACTION WITH CONSISTENT SNAPSHOT;
--echo # state does not change, and therefore isn't reported
START TRANSACTION WITH CONSISTENT SNAPSHOT;
COMMIT;
--echo

--echo # show that session_track_transaction_info="CHARACTERISTICS" shows more edges
SET session_track_transaction_info="CHARACTERISTICS";
--echo # normal syntax: TR->T->0
START TRANSACTION WITH CONSISTENT SNAPSHOT;
COMMIT AND CHAIN;
COMMIT;
--echo # normal syntax: T->T->0
START TRANSACTION;
COMMIT AND CHAIN;
COMMIT;
--echo # pathological syntax: TR->TR->0
START TRANSACTION WITH CONSISTENT SNAPSHOT;
START TRANSACTION WITH CONSISTENT SNAPSHOT;
COMMIT;
--echo


--echo # chistics and interaction of implicit trx and explicit trx 
CREATE TABLE t1 (f1 INT) ENGINE="InnoDB";
SET autocommit=0;
SET TRANSACTION READ ONLY;
--error ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
INSERT INTO t1 VALUES(1);
ROLLBACK;
SET TRANSACTION READ WRITE;
# does not prevent further one-shots:
SET TRANSACTION READ ONLY;
SET TRANSACTION READ WRITE;
INSERT INTO t1 VALUES(1);
# in implicit transaction, can't set one-shots here using SET TRANSACTION
--error ER_CANT_CHANGE_TX_CHARACTERISTICS
SET TRANSACTION READ WRITE;
# we can set one-shots using START TRANSACTION though, as that commits
# an ongoing implicit transaction
START TRANSACTION READ ONLY;
# implicit COMMIT
DROP TABLE t1;

CREATE TABLE t1 (f1 INT) ENGINE="InnoDB";
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
# start implicit trx
INSERT INTO t1 VALUES(1);
--echo # implicit commit (chistics item here, clearing isolation level):
ALTER TABLE t1 ADD COLUMN f2 INT;
START TRANSACTION;
ROLLBACK;
--echo
# start implicit trx
INSERT INTO t1 VALUES(2,2);
--echo # implicit commit (no chistics item here):
ALTER TABLE t1 ADD COLUMN f3 INT;
START TRANSACTION;
ROLLBACK;
DROP TABLE t1;

SET autocommit=1;

# cleanup
SET session_track_transaction_info="STATE";
--echo



--echo ########################################################################
--echo #
--echo # show that table access reporting works in multi-statements
--echo #

--echo # multi-stmt #1
CREATE TABLE t2 (f1 INT) ENGINE="MyISAM";
BEGIN;

# COMMIT clears state, table write is not recorded as outside transaction,
# then transaction start is recorded:
delimiter |;

COMMIT; INSERT INTO t2 VALUES (1); BEGIN; |

delimiter ;|

COMMIT;
DROP TABLE t2;


--echo # multi-stmt #2
CREATE TABLE t1 (f1 INT) ENGINE="InnoDB";
CREATE TABLE t2 (f1 INT) ENGINE="MyISAM";
BEGIN;

# COMMIT clears state, table write is not recorded as outside transaction,
# then transaction start is recorded, finally a write is added:
delimiter |;

COMMIT; INSERT INTO t2 VALUES (1); BEGIN; INSERT INTO t1 VALUES (99); |

delimiter ;|

COMMIT;
DROP TABLE t1;
DROP TABLE t2;
--echo



--echo ########################################################################
--echo #
--echo # show that table access reporting works in Stored Functions (SF)
--echo #

CREATE TABLE t1 (f1 INT) ENGINE="InnoDB";
INSERT INTO t1 VALUES (1);
DELIMITER |;

--echo # create func1() in system table:
CREATE FUNCTION func1()
  RETURNS INTEGER
BEGIN
  SET @dummy = 0;
  IF (SELECT * FROM t1) THEN
    SET @dummy = 1;
  END IF;
  RETURN @dummy;
END|

DELIMITER ;|

--echo # func1() reads a trx table (and is read from a system table!):
BEGIN;
SELECT func1();
COMMIT;
DROP TABLE t1;
--echo # drop func1() from system table:
DROP FUNCTION func1;



--echo ########################################################################
--echo #
--echo # show that reporting works for Stored Procedures (SP)
--echo #

CREATE TABLE t1 (f1 INT) ENGINE="InnoDB";
CREATE TABLE t2 (f1 INT) ENGINE="MyISAM";
INSERT INTO t1 VALUES (1);
INSERT INTO t2 VALUES (2);

DELIMITER |;

CREATE PROCEDURE proc1()
BEGIN
  SET @dummy = 0;
  IF (SELECT f1 FROM t1) THEN
    SET @dummy = 1;
  END IF;
END|

CREATE PROCEDURE proc2()
BEGIN
  CALL proc1();
  UPDATE t1 SET f1=4;
END|

CREATE PROCEDURE proc3()
BEGIN
  DECLARE x CHAR(36);
  SET x=UUID();
END|

CREATE PROCEDURE proc4(x CHAR(36))
BEGIN
END|

CREATE PROCEDURE proc5()
BEGIN
  SELECT f1 FROM t1;
  SELECT f1 FROM t2;
END|

CREATE PROCEDURE proc6a()
BEGIN
  IF (SELECT f1 FROM t1) THEN
    SET @dummy = 1;
  END IF;
  ALTER TABLE t1 ADD COLUMN f2 INT;
  IF (SELECT f1 FROM t2) THEN
    SET @dummy = 1;
  END IF;
END|

CREATE PROCEDURE proc6b()
BEGIN
  SELECT f1 FROM t1;
  ALTER TABLE t1 ADD COLUMN f3 INT;
  SELECT f1 FROM t2;
END|

CREATE PROCEDURE proc7(x INT)
BEGIN
  SELECT f1   FROM t1;
  SELECT f1*2 FROM t1;
END|

CREATE PROCEDURE proc8(x INT)
BEGIN
  SELECT f1   FROM t1;
  IF (SELECT f1 FROM t2) THEN
    SET @dummy = 1;
  END IF;
END|

CREATE PROCEDURE proc9(x INT)
BEGIN
  SELECT f1   FROM t1;
  IF (SELECT f1 FROM t1) THEN
    SET @dummy = 1;
  END IF;
END|

DELIMITER ;|

BEGIN;
--echo # example unsafe call:
CALL proc3();
--echo # report on tables accessed within SP:
CALL proc1();
--echo # report on tables accessed within all (nested) SP:
CALL proc2();
COMMIT;
BEGIN;
CALL proc4(UUID());
COMMIT;

--echo # multiple result sets:
--echo # autocommit=1, not in a transaction, no tracker item:
CALL proc5();
--echo

BEGIN;
--echo # first  SELECT adds R/S to present T and renders a tracker item;
--echo # second SELECT add r flag and renders another tracker item
CALL proc5();
COMMIT;

SET autocommit=0;
--echo # first  SELECT renders I/R/S tracker item;
--echo # second SELECT add r flag and renders another tracker item
CALL proc5();
COMMIT;
--echo

BEGIN;
--echo # first  SELECT adds R/S to present T and renders a tracker item;
--echo # second SELECT add r flag and renders another tracker item
CALL proc5();
COMMIT;
--echo

--echo # multiple result sets; implicit commit between them
BEGIN;
--echo # first  SELECT adds R/S to present T and renders a tracker item;
--echo # second SELECT add r flag and renders another tracker item
CALL proc6b();
COMMIT;
BEGIN;
--echo # first  SELECT adds R/S to present T and renders a tracker item;
--echo # second SELECT add r flag and renders another tracker item
CALL proc6a();
COMMIT;
--echo

--echo # multiple result sets; sub-query as argument, autocommit==0
BEGIN;
# add S to tracker item
SELECT 1 FROM DUAL;
CALL proc7((SELECT f1 FROM t2));
COMMIT;

SET autocommit=1;

--echo # multiple result sets; sub-query as argument, autocommit==1
BEGIN;
# add S to tracker item
SELECT 1 FROM DUAL;
CALL proc7((SELECT f1 FROM t2));
COMMIT;

--echo # not in a transaction, no tracking
CALL proc8((SELECT f1 FROM t2));
--echo

BEGIN;
--echo # body sets R/S in select, and r in sub-select
CALL proc8((SELECT f1 FROM t2));
COMMIT;
--echo

BEGIN;
--echo # argument sets r, body sets R
CALL proc9((SELECT f1 FROM t2));
COMMIT;
--echo

DROP PROCEDURE proc1;
DROP PROCEDURE proc2;
DROP PROCEDURE proc3;
DROP PROCEDURE proc4;
DROP PROCEDURE proc5;
DROP PROCEDURE proc6a;
DROP PROCEDURE proc6b;
DROP PROCEDURE proc7;
DROP PROCEDURE proc8;
DROP PROCEDURE proc9;
DROP TABLE t1;
DROP TABLE t2;



--echo ########################################################################
--echo #
--echo # interaction with system tables
--echo #

CREATE TABLE t2 (f1 INT) ENGINE="MyISAM";
BEGIN;
# CONVERT_TZ() accesses a transactional system table in an attached
# transaction. This is an implementation detail / artifact that does
# not concern the user transaction, so we hide it (as we do all state
# from attached transactions).
SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');
COMMIT;
DROP TABLE t2;

--echo #
--echo # log tables
--echo #

SET @old_log_output=          @@global.log_output;
SET @old_general_log=         @@global.general_log;
SET @old_general_log_file=    @@global.general_log_file;

TRUNCATE TABLE mysql.general_log;

SET GLOBAL log_output =       'TABLE';
SET GLOBAL general_log=       'ON';

BEGIN;
# Example query to be logged to the log table, general_log.
# That table access does not become part of our state:
SELECT 1 FROM DUAL;
# Show that the above query was actually logged.
# THIS (read) access will be flagged, as it's part of the user's transaction.
SELECT " -> ", argument FROM mysql.general_log WHERE argument LIKE '% DUAL' AND (command_type!='Prepare');
ROLLBACK;

TRUNCATE TABLE mysql.general_log;

SET GLOBAL general_log_file=  @old_general_log_file;
SET GLOBAL general_log=       @old_general_log;
SET GLOBAL log_output=        @old_log_output;


--echo ########################################################################
--echo #
--echo # show that table access reporting works with LOCK TABLES
--echo #

CREATE TABLE t1 (f1 INT) ENGINE="InnoDB";
CREATE TABLE t2 (f1 INT) ENGINE="MyISAM";
SET autocommit=0;
SELECT 1  FROM DUAL;
SELECT f1 FROM t1;
--echo # no LOCK held this time, so no implicit commit:
UNLOCK TABLES;
--echo # LOCK TABLES pre-commits:
LOCK TABLES t1 WRITE;
INSERT INTO t1 VALUES (1);
INSERT INTO t1 VALUES (2);
SELECT f1 FROM t1;
COMMIT;
SET TRANSACTION READ ONLY;
SET TRANSACTION READ WRITE;
UNLOCK TABLES;

--echo
SET autocommit=1;
LOCK TABLE t1 WRITE, t2 WRITE;
INSERT INTO t2 VALUES (3);
INSERT INTO t1 VALUES (3);
SELECT f1 FROM t1 WHERE f1 > 2;
UNLOCK TABLES;

--echo # don't report chistics for autocommits while LOCK is held
SET SESSION session_track_transaction_info="CHARACTERISTICS";
LOCK TABLE t1 WRITE;
INSERT INTO t1 VALUES (3);
SELECT f1 FROM t1 WHERE f1 > 2;
UNLOCK TABLES;
SET session_track_transaction_info="STATE";

DROP TABLE t1;
DROP TABLE t2;



--echo ########################################################################
--echo #
--echo # query cache
--echo #

# turn on, tune in, ...
SELECT @@global.query_cache_size INTO @old_qc_size;
SET GLOBAL  query_cache_size = 999424;
SET SESSION query_cache_type = 1;
SELECT @@global.query_cache_size;
SELECT @@session.query_cache_type;

CREATE TABLE t1 (f1 INT) ENGINE="MyISAM";

INSERT INTO t1 VALUES (1), (2), (3);

# ... burn out:
--echo # show we can't add queries to the cache while tracking:
BEGIN;
# This query has new state (trx read, result set) and can't be added:
SELECT     f1 FROM t1 WHERE f1 > 1;
# This query has no new state/tracker item, and still can't be added:
SELECT f1 FROM t1 WHERE f1 > 1;
COMMIT;
SHOW STATUS LIKE 'Qcache_queries_in_cache';

# Temporarily stop tracking ...
SET SESSION session_track_transaction_info="OFF";
# ... so we can add a query to the cache:
SELECT f1 FROM t1 WHERE f1 > 1;
SHOW STATUS LIKE 'Qcache_queries_in_cache';
# Satisfy query from cache:
SELECT f1 FROM t1 WHERE f1 > 1;
SHOW STATUS LIKE 'Qcache_hits';
# Turn tracking back on:
SET SESSION session_track_transaction_info="STATE";
# Query is still in cache ...
SHOW STATUS LIKE 'Qcache_queries_in_cache';
# ... but we can no longer access it:
SELECT f1 FROM t1 WHERE f1 > 1;
SHOW STATUS LIKE 'Qcache_hits';

RESET QUERY CACHE;
FLUSH STATUS;

DROP TABLE t1;

SET SESSION query_cache_type = 0;
SET GLOBAL  query_cache_size = @old_qc_size;



--echo ########################################################################
--echo #
--echo # XA
--echo #

CREATE TABLE t1 (f1 int) ENGINE="InnoDB";
SET SESSION session_track_transaction_info="CHARACTERISTICS";

--echo # XA ROLLBACK
XA START 'test1';
INSERT t1 VALUES (1);
XA END 'test1';
XA PREPARE 'test1';
XA ROLLBACK 'test1';

--echo # XA COMMIT
XA START 'test2', 'yy';
INSERT t1 VALUES (2);
XA END 'test2', 'yy';
XA PREPARE 'test2', 'yy';
XA COMMIT 'test2', 'yy';

--echo # XA COMMIT ONE PHASE
XA START 'test3','xx',5;
INSERT t1 VALUES (3);
XA END 'test3','xx',5;
XA COMMIT 'test3','xx',5 ONE PHASE;

SET SESSION session_track_transaction_info="OFF";
DROP TABLE t1;



--echo ########################################################################
--echo #
--echo # cleanup
--echo #

--disable_session_track_info

SET SESSION session_track_system_variables= @old_track_list;
SET SESSION session_track_state_change=@old_track_enable;
SET SESSION session_track_transaction_info=@old_track_tx;

# ends

Man Man