################################################################################
# t/partition_basic_innodb.test                                                #
#                                                                              #
# Purpose:                                                                     #
#  Tests around Create Partitioned table using DATA/INDEX DIR                  #
#        InnoDB branch                                                         #
#                                                                              #
#------------------------------------------------------------------------------#
# Original Author: mleich                                                      #
# Original Date: 2006-03-05                                                    #
# Change Author: mattiasj                                                      #
# Change Date: 2008-02-05                                                      #
# Change: copied it from partition_basic_innodb.test and kept DATA DIR         #
# Change Author: mattiasj                                                      #
# Change Date: 2008-03-16                                                      #
# Change: Replaced all test with alter -> myisam, since innodb does not support#
# Change Author: Kevin lewis                                                   #
# Change Date: 2012-03-02                                                      #
# Change: WL5980 activates DATA DIRECTORY for InnoDB                           #
################################################################################

# NOTE: As of WL5980, InnoDB supports DATA DIRECTORY, but not INDEX DIRECTORY.
#       See innodb.innodb-tablespace for tests using partition engine, innodb
#       and DATADIRECTORY.  The purpose of this test is to show that a
#       partitioned table remembers the DATA/INDEX DIR and it is used if
#       altered to MyISAM
#
--echo #
--echo # Verify that the DATA/INDEX DIR is stored and used if ALTER to MyISAM.
--echo #
--source include/have_innodb.inc
# The server must support partitioning.
--source include/have_partition.inc
# The server must support symlink for DATA/INDEX DIRECTORY.
--source include/have_symlink.inc
# windows does not support symlink for DATA/INDEX DIRECTORY.
--source include/not_windows.inc

# Does not work with --embedded
--source include/not_embedded.inc

--disable_query_log
let $MYSQLD_DATADIR= `select @@datadir`;

# These values can change during the test
LET $innodb_file_per_table_orig=`select @@innodb_file_per_table`;
LET $innodb_strict_mode_orig=`select @@session.innodb_strict_mode`;
--enable_query_log

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

--mkdir $MYSQLTEST_VARDIR/mysql-test-data-dir
--mkdir $MYSQLTEST_VARDIR/mysql-test-idx-dir

SET SESSION innodb_strict_mode = ON;

--echo #
--echo # InnoDB only supports DATA DIRECTORY with innodb_file_per_table=ON
--echo #
SET GLOBAL innodb_file_per_table = OFF;
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--error ER_ILLEGAL_HA
eval CREATE TABLE t1 (c1 INT)  ENGINE = InnoDB
PARTITION BY HASH (c1) (
  PARTITION p0
    DATA DIRECTORY = '$MYSQLTEST_VARDIR/mysql-test-data-dir'
    INDEX DIRECTORY = '$MYSQLTEST_VARDIR/mysql-test-idx-dir',
  PARTITION p1
    DATA DIRECTORY = '$MYSQLTEST_VARDIR/mysql-test-data-dir'
    INDEX DIRECTORY = '$MYSQLTEST_VARDIR/mysql-test-idx-dir'
);
--replace_result ./ MYSQLD_DATADIR/  $MYSQLD_DATADIR MYSQLD_DATADIR
SHOW WARNINGS;

--echo #
--echo # InnoDB is different from MyISAM in that it uses a text file
--echo # with an '.isl' extension instead of a symbolic link so that
--echo # the tablespace can be re-located on any OS. Also, instead of
--echo # putting the file directly into the DATA DIRECTORY,
--echo # it adds a folder under it with the name of the database.
--echo # Since strict mode is off, InnoDB ignores the INDEX DIRECTORY
--echo # and it is no longer part of the definition.
--echo #
SET SESSION innodb_strict_mode = OFF;
SET GLOBAL innodb_file_per_table = ON;
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
eval CREATE TABLE t1 (c1 INT) ENGINE = InnoDB
PARTITION BY HASH (c1)
(PARTITION p0
 DATA DIRECTORY = '$MYSQLTEST_VARDIR/mysql-test-data-dir'
 INDEX DIRECTORY = '$MYSQLTEST_VARDIR/mysql-test-idx-dir',
 PARTITION p1
 DATA DIRECTORY = '$MYSQLTEST_VARDIR/mysql-test-data-dir'
 INDEX DIRECTORY = '$MYSQLTEST_VARDIR/mysql-test-idx-dir'
);
SHOW WARNINGS;

--echo # Verifying .frm, .par, .isl & .ibd files
--echo ---- MYSQLD_DATADIR/test
--list_files $MYSQLD_DATADIR/test
--echo ---- MYSQLTEST_VARDIR/mysql-test-data-dir/test
--list_files $MYSQLTEST_VARDIR/mysql-test-data-dir/test
--echo # The ibd tablespaces should not be directly under the DATA DIRECTORY
--echo ---- MYSQLTEST_VARDIR/mysql-test-data-dir
--list_files $MYSQLTEST_VARDIR/mysql-test-data-dir
--echo ---- MYSQLTEST_VARDIR/mysql-test-idx-dir
--list_files $MYSQLTEST_VARDIR/mysql-test-idx-dir

FLUSH TABLES;
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
SHOW CREATE TABLE t1;

--echo #
--echo # Verify that the DATA/INDEX DIRECTORY is stored and used if we
--echo # ALTER TABLE to MyISAM.
--echo #
ALTER TABLE t1 engine=MyISAM;
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
SHOW CREATE TABLE t1;
--echo # Verifying .frm, .par and MyISAM files (.MYD, MYI)
--echo ---- MYSQLD_DATADIR/test
--list_files $MYSQLD_DATADIR/test
--echo ---- MYSQLTEST_VARDIR/mysql-test-data-dir
--list_files $MYSQLTEST_VARDIR/mysql-test-data-dir
--echo ---- MYSQLTEST_VARDIR/mysql-test-idx-dir
--list_files $MYSQLTEST_VARDIR/mysql-test-idx-dir

--echo #
--echo # Now verify that the DATA DIRECTORY is used again if we
--echo # ALTER TABLE back to InnoDB.
--echo #
SET SESSION innodb_strict_mode = ON;
ALTER TABLE t1 engine=InnoDB;
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
SHOW CREATE TABLE t1;
--echo # Verifying .frm, .par, .isl and InnoDB .ibd files
--echo ---- MYSQLD_DATADIR/test
--list_files $MYSQLD_DATADIR/test
--echo ---- MYSQLTEST_VARDIR/mysql-test-data-dir
--list_files $MYSQLTEST_VARDIR/mysql-test-data-dir
--echo ---- MYSQLTEST_VARDIR/mysql-test-idx-dir
--list_files $MYSQLTEST_VARDIR/mysql-test-idx-dir
--echo ---- MYSQLTEST_VARDIR/mysql-test-data-dir/test
--list_files $MYSQLTEST_VARDIR/mysql-test-data-dir/test

DROP TABLE t1;

--echo #
--echo # Cleanup
--echo #

--rmdir $MYSQLTEST_VARDIR/mysql-test-data-dir/test
--rmdir $MYSQLTEST_VARDIR/mysql-test-data-dir
--rmdir $MYSQLTEST_VARDIR/mysql-test-idx-dir

--disable_query_log
EVAL SET GLOBAL innodb_file_per_table=$innodb_file_per_table_orig;
EVAL SET SESSION innodb_strict_mode=$innodb_strict_mode_orig;
--enable_query_log



