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

#
# Bug #32833: : Falcon: crash creating utf8 index
#
--echo *** Bug #32833 ***

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

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

--echo # Create table
CREATE TABLE t1 (int_column INT, char_column CHAR(5) CHARACTER SET UTF32)
  PARTITION BY KEY(char_column);

--echo # Create and call procedure for populating table
SET @@autocommit=0;
delimiter //;
CREATE PROCEDURE p1 ()
BEGIN
  DECLARE v_rownum INT DEFAULT 0;
  DECLARE v_random_character CHAR(1);
  DECLARE v_random_string VARCHAR(50);
  WHILE v_rownum < 1000000 DO
    IF V_rownum MOD 101 = 0 THEN COMMIT; END IF;
    # IF V_rownum MOD 1000 = 0 THEN SELECT v_rownum; END IF;
    SET @stmt1 = CONCAT('INSERT INTO t1 VALUES (',
      v_rownum, ',', '0x',v_rownum, ');');
    # SELECT v_rownum,v_random_string,@stmt1;
    PREPARE stmt1 FROM @stmt1;
    EXECUTE stmt1;
    SET v_rownum = v_rownum + 357;
  END WHILE;
END//
DELIMITER ;//
CALL p1();

SELECT count(*) FROM t1;

--echo # Change column from UTF32 to UTF8
--disable_warnings
ALTER TABLE t1 MODIFY COLUMN char_column CHAR(5) CHARACTER SET utf8;
--enable_warnings

# ----------------------------------------------------- #
# --- Test                                          --- #
# ----------------------------------------------------- #
--echo # Add index to UTF8 column
CREATE INDEX i ON t1 (char_column);

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

# ----------------------------------------------------- #
# --- Final cleanup                                 --- #
# ----------------------------------------------------- #
DROP TABLE t1;
DROP PROCEDURE p1;
