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

#
# BUG#33404 - Falcon ignores partition-level TABLESPACE option
#
--echo *** Bug #33404 ***

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

# We have to disable errors here, because DROP TABLESPACE
# does not know about IF EXISTS.
--error 0,ER_NO_SUCH_TABLESPACE
eval DROP TABLESPACE ts1 Engine $engine;
--error 0,ER_NO_SUCH_TABLESPACE
eval DROP TABLESPACE ts2 Engine $engine;
--error 0,ER_NO_SUCH_TABLESPACE
eval DROP TABLESPACE ts3 Engine $engine;

eval CREATE TABLESPACE ts1 ADD DATAFILE 'ts1.fts' Engine $engine;
eval CREATE TABLESPACE ts2 ADD DATAFILE 'ts2.fts' Engine $engine;
eval CREATE TABLESPACE ts3 ADD DATAFILE 'ts3.fts' Engine $engine;

# ----------------------------------------------------- #
# --- Test                                          --- #
# ----------------------------------------------------- #
CREATE TABLE t1 (a INT) TABLESPACE ts1
PARTITION BY RANGE(a) SUBPARTITION BY HASH(a) (
  PARTITION p1 VALUES LESS THAN (100) TABLESPACE ts2 (
    SUBPARTITION p1s1 TABLESPACE ts3,
    SUBPARTITION p1s2
  ),
  PARTITION p2 VALUES LESS THAN MAXVALUE (
    SUBPARTITION p2s1,
    SUBPARTITION p2s2
  )
);
SHOW CREATE TABLE t1;

ALTER TABLE t1 REMOVE PARTITIONING;
SHOW CREATE TABLE t1;

ALTER TABLE t1 TABLESPACE ts1
PARTITION BY RANGE(a) SUBPARTITION BY HASH(a) (
  PARTITION p1 VALUES LESS THAN (100) TABLESPACE ts2 (
    SUBPARTITION p1s1 TABLESPACE ts3,
    SUBPARTITION p1s2
  ),
  PARTITION p2 VALUES LESS THAN (200) (
    SUBPARTITION p2s1,
    SUBPARTITION p2s2
  )
);
SHOW CREATE TABLE t1;

ALTER TABLE t1 ADD PARTITION (PARTITION p3 VALUES LESS THAN MAXVALUE);
SHOW CREATE TABLE t1;

ALTER TABLE t1 REORGANIZE PARTITION p3 INTO (PARTITION p3 VALUES LESS THAN
MAXVALUE TABLESPACE ts1);
SHOW CREATE TABLE t1;

ALTER TABLE t1 REORGANIZE PARTITION p3 INTO (PARTITION p3 VALUES LESS THAN
MAXVALUE TABLESPACE ts2);
SHOW CREATE TABLE t1;

ALTER TABLE t1 REORGANIZE PARTITION p1 INTO (PARTITION p1 VALUES LESS THAN
(100) TABLESPACE ts2);
SHOW CREATE TABLE t1;

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

# ----------------------------------------------------- #
# --- Final cleanup                                 --- #
# ----------------------------------------------------- #
DROP TABLE t1;
eval DROP TABLESPACE ts1 Engine $engine;
eval DROP TABLESPACE ts2 Engine $engine;
eval DROP TABLESPACE ts3 Engine $engine;
