--source include/have_falcon.inc

#
# Bug #22181: Query cache becomes obsolete with two
#                  interleaving transactions
#
--echo *** Bug #22181 ***

# ----------------------------------------------------- #
# --- Initialisation                                --- #
# ----------------------------------------------------- #
let $engine = 'Falcon';
eval SET @@storage_engine = $engine;

--disable_warnings
DROP DATABASE IF EXISTS falcon4;
--enable_warnings

CREATE DATABASE falcon4;

# Establish connection1
connect (connection1,localhost,root,,falcon4);
eval SET @@storage_engine = $engine;
USE falcon4;

connection default;
USE falcon4;
# This should be 'YES'.
SHOW VARIABLES LIKE 'have_query_cache';

# There should be no warnings.
SELECT @@GLOBAL.query_cache_size INTO @previous_query_cache_size;
SET GLOBAL query_cache_size = 200000;
SET @@autocommit=0;
CREATE TABLE t2 (s1 int, s2 varchar(1000), key(s1));
INSERT INTO t2 VALUES (1,repeat('a',1000)),(2,repeat('a',1000));
COMMIT;

# ----------------------------------------------------- #
# --- Test                                          --- #
# ----------------------------------------------------- #
START TRANSACTION;
UPDATE t2 SET s2 = 'w' WHERE s1 = 10;
SELECT SQL_CACHE count(*) FROM t2 WHERE s2 = 'w';

connection connection1;
COMMIT;
USE falcon4;
START TRANSACTION;

# Matches T1's SELECT condition.
INSERT INTO t2 VALUES (-1,'w');
COMMIT;

connection default;
SELECT SQL_CACHE count(*) FROM t2 WHERE s2 = 'w';
COMMIT;

# The result is 0. With engine=innodb, the result would be 1.
SELECT SQL_CACHE count(*) FROM t2 WHERE s2 = 'w';

connection connection1;
# The result is 0. With engine=innodb, the result would be 1.
SELECT SQL_CACHE count(*) FROM t2 WHERE s2 = 'w';

# ----------------------------------------------------- #
# --- Check                                         --- #
# ----------------------------------------------------- #
SELECT count(*) FROM t2;

# ----------------------------------------------------- #
# --- Final cleanup                                 --- #
# ----------------------------------------------------- #
disconnect connection1;
connection default;
SET GLOBAL query_cache_size = @previous_query_cache_size;
DROP DATABASE falcon4;
