--source include/have_falcon.inc
--source include/have_partition.inc

#
# Bug #26828: Falcon: crash with two connections and partitions
#
--echo *** Bug #26828 ***

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

--disable_warnings
DROP SCHEMA IF EXISTS db1;
--enable_warnings

SELECT @@GLOBAL.falcon_consistent_read INTO @previous_falcon_consistent_read;
SET GLOBAL falcon_consistent_read = off;

CREATE SCHEMA db1;
USE db1;
CREATE TABLE t1 (a int)
PARTITION BY list(a) (
  PARTITION p1 VALUES IN (1)
);

--echo # Establish connection conn1 (user = root)
connect (conn1,localhost,root,,);
eval SET @@storage_engine = $engine;
USE db1;

# ----------------------------------------------------- #
# --- Test                                          --- #
# ----------------------------------------------------- #
--echo # Switch to connection default
connection default;
DELIMITER //;
INSERT INTO t1 VALUES (1)//
CREATE PROCEDURE p1 ()
BEGIN
  DECLARE v int DEFAULT 0;
  WHILE v < 50 DO
    /* IF v mod 100 = 0 THEN
      SELECT v;
    END IF; */
    UPDATE t1 SET a = 1;
    SET v = v + 1;
  END WHILE;
END//
DELIMITER ;//
--send CALL p1()

--echo # Switch to connection conn1
connection conn1;
CALL p1();

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

# ----------------------------------------------------- #
# --- Final cleanup                                 --- #
# ----------------------------------------------------- #
--echo # Switch to connection default
connection default;
disconnect conn1;
SET GLOBAL falcon_consistent_read = @previous_falcon_consistent_read;
DROP TABLE t1;
DROP SCHEMA db1;
USE test;
