--source include/have_falcon.inc
#--disable_abort_on_error
#
# Bug #34351_D: Update Conflict on non-overlapping transactions
#
--echo *** Bug #34351_D ***

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

--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings

--echo # Establish connection conn1 (user = root)
connect (conn1,localhost,root,,);
SET @@autocommit = 1;
SET FALCON_CONSISTENT_READ=OFF;

--echo # Switch to connection default
connection default;
SET @@autocommit = 1;
SET FALCON_CONSISTENT_READ=OFF;

CREATE TABLE t1 (
  t1_autoinc INTEGER NOT NULL AUTO_INCREMENT,
  t1_uuid CHAR(36),
  PRIMARY KEY (t1_autoinc), KEY (t1_uuid)
) ENGINE = Falcon;

# ----------------------------------------------------- #
# --- Test #1  Filter on UUID Without a transaction --- #
# ----------------------------------------------------- #

--echo # Test #1  Filter on UUID Without a transaction
SET @default_uuid = UUID();
INSERT INTO t1 (t1_uuid) VALUES (@default_uuid);
SELECT t1_autoinc FROM t1 ORDER BY t1_autoinc;
START TRANSACTION;
DELETE FROM t1 WHERE t1_uuid = (@default_uuid);

--echo # Switch to connection conn1
connection conn1;
SET @conn1_uuid = UUID();
SELECT t1_autoinc FROM t1 ORDER BY t1_autoinc;
INSERT INTO t1 (t1_uuid) VALUES (@conn1_uuid);
SELECT t1_autoinc FROM t1 ORDER BY t1_autoinc;
--send DELETE FROM t1 WHERE t1_uuid = (@conn1_uuid)

--echo # Switch to connection default
connection default;
SELECT t1_autoinc FROM t1 ORDER BY t1_autoinc;
COMMIT;

--echo # Switch to connection conn1
connection conn1;
reap;
SELECT t1_autoinc FROM t1 ORDER BY t1_autoinc;

# ----------------------------------------------------- #
# --- Test #2 Filter on UUID With a transaction     --- #
# ----------------------------------------------------- #

--echo # Test #2 Filter on UUID With a transaction
--echo # Switch to connection default
connection default;
START TRANSACTION;
SET @default_uuid = UUID();
INSERT INTO t1 (t1_uuid) VALUES (@default_uuid);
SELECT t1_autoinc FROM t1 ORDER BY t1_autoinc;
DELETE FROM t1 WHERE t1_uuid = (@default_uuid);
SELECT t1_autoinc FROM t1 ORDER BY t1_autoinc;

--echo # Switch to connection conn1
connection conn1;
SET @conn1_uuid = UUID();
START TRANSACTION;
SELECT t1_autoinc FROM t1 ORDER BY t1_autoinc;
INSERT INTO t1 (t1_uuid) VALUES (@conn1_uuid);
SELECT t1_autoinc FROM t1 ORDER BY t1_autoinc;
--send DELETE FROM t1 WHERE t1_uuid = (@conn1_uuid)

--echo # Switch to connection default
connection default;
SELECT t1_autoinc FROM t1 ORDER BY t1_autoinc;
COMMIT;

--echo # Switch to connection conn1
connection conn1;
reap;
SELECT t1_autoinc FROM t1 ORDER BY t1_autoinc;
COMMIT;


# ----------------------------------------------------- #
# --- Test #3 Filter on INT Without a transaction   --- #
# ----------------------------------------------------- #
--echo # Test #3 Filter on INT With a transaction
--echo # Switch to connection default
connection default;
START TRANSACTION;
SET @default_uuid = UUID();
INSERT INTO t1 VALUES (11, @default_uuid);
SELECT t1_autoinc FROM t1 ORDER BY t1_autoinc;
DELETE FROM t1 WHERE t1_uuid = (@default_uuid);
SELECT t1_autoinc FROM t1 ORDER BY t1_autoinc;

--echo # Switch to connection conn1
connection conn1;
SET @conn1_uuid = UUID();
INSERT INTO t1 VALUES (12, @conn1_uuid);
SELECT t1_autoinc FROM t1 ORDER BY t1_autoinc;
DELETE FROM t1 WHERE t1_autoinc = 12;

--echo # Switch to connection default
connection default;
SELECT t1_autoinc FROM t1 ORDER BY t1_autoinc;
COMMIT;

# ----------------------------------------------------- #
# --- Check                                         --- #
# ----------------------------------------------------- #

--echo # Switch to connection conn1
connection conn1;
SELECT t1_autoinc FROM t1 ORDER BY t1_autoinc;

--echo # Switch to connection default
connection default;
SELECT t1_autoinc FROM t1 ORDER BY t1_autoinc;

# ----------------------------------------------------- #
# --- Final cleanup                                 --- #
# ----------------------------------------------------- #
disconnect conn1;
DROP TABLE IF EXISTS t1;
