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

#
# Bug #22845: Falcon: hang on partition drop
#
--echo *** Bug #22845 ***

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

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

CREATE DATABASE db1;
USE db1;

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

--echo # Switch to connection default
connection default;
SET @@autocommit = 0;

CREATE TABLE t1 (a int) PARTITION BY LIST (a) (
  PARTITION p1 VALUES IN (1),
  PARTITION p2 VALUES IN (2),
  PARTITION p3 VALUES IN (null)
);
START TRANSACTION;

# ----------------------------------------------------- #
# --- Test                                          --- #
# ----------------------------------------------------- #
--echo # Switch to connection conn1
connection conn1;
START TRANSACTION;
INSERT INTO t1 VALUES (2);

--echo # Switch to connection default
connection default;
# With Falcon we cannot do DDL on objects with
# pending transactions.
--error ER_CANT_LOCK
ALTER TABLE t1 DROP PARTITION p2;

--echo # Switch to connection conn1
connection conn1;
COMMIT;

--echo # Switch to connection default
connection default;
ALTER TABLE t1 DROP PARTITION p2;
COMMIT;

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

# ----------------------------------------------------- #
# --- Final cleanup                                 --- #
# ----------------------------------------------------- #
connection default;
disconnect conn1;
DROP DATABASE db1;
