########################################################################
# Bug 1017192: Server crashes in add_identifier on concurrent
#              ALTER TABLE and SHOW ENGINE INNODB STATUS
# We run concurrent ALTER TABLE PARTITION and execute
# SHOW ENGINE INNODB STATUS exactly at the moment when
# temporary tables already created and locked.
########################################################################

--source include/have_partition.inc
--source include/have_innodb.inc
--source include/have_debug_sync.inc

SET DEBUG_SYNC='reset';

CREATE TABLE IF NOT EXISTS t1 (`a` INT) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1),(2),(3),(4);

--source include/count_sessions.inc
--connect (con1,localhost,root,,)

--connection default
SET DEBUG_SYNC='after_copy_data_between_tables SIGNAL run_show_innodb_status
                   WAIT_FOR show_innodb_status_done';
--send ALTER TABLE t1 PARTITION BY HASH (`a`) PARTITIONS 4 
--connection con1
SET DEBUG_SYNC='now WAIT_FOR run_show_innodb_status';
# We catch the moment when SHOW ENGINE INNODB STATUS should produce lines like:
#   TABLE LOCK table `test`.`#sql-14021_2#P#p1` /* Partition `p1` */ trx id 506 lock mode IX
#   TABLE LOCK table `test`.`#sql-14021_2#P#p2` /* Partition `p2` */ trx id 506 lock mode IX
#   TABLE LOCK table `test`.`#sql-14021_2#P#p3` /* Partition `p3` */ trx id 506 lock mode IX
#   TABLE LOCK table `test`.`#sql-14021_2#P#p0` /* Partition `p0` */ trx id 506 lock mode IX
# This cause segmentation fault because of incorrect handling of table names
# which look like `#sql-14021_2#P#p0`
--disable_result_log
SHOW ENGINE INNODB STATUS;
--enable_result_log
SET DEBUG_SYNC='now SIGNAL show_innodb_status_done';
--connection default
--reap

disconnect con1;

DROP TABLE t1;
SET DEBUG_SYNC='reset';

--source include/wait_until_count_sessions.inc
