--source include/have_innodb.inc

#
# MDEV-11724: InnoDB: Failing assertion: len <= col->len || ((col->mtype) == 5 || (col->mtype) == 16 || (col->mtype) == 14) || (((col->mtype) == 15 || (col->mtype) == 16) && len == 2 * 2 * sizeof(double)) || (col->len == 0 && col->mtype == 1)
#

CREATE TABLE t1 ( 
 y YEAR NULL,
 i SMALLINT NULL,
 c VARCHAR(8) NOT NULL DEFAULT '',
 vi SMALLINT AS (i) VIRTUAL,
 INDEX(y)
) ENGINE=InnoDB;

SHOW CREATE TABLE t1;
SELECT * FROM t1 WHERE y BETWEEN 2012 AND 2016 FOR UPDATE;
INSERT INTO t1 (i) VALUES (1),(2);
SELECT * FROM t1 WHERE y BETWEEN 2012 AND 2016 FOR UPDATE;
DROP TABLE t1;

#
# MDEV-11725: InnoDB: Failing assertion: !rec || !cmp_dtuple_rec(tuple, rec, *offsets)
#

CREATE TABLE t1 ( 
 y YEAR NULL,
 i SMALLINT NULL,
 vi SMALLINT AS (i) VIRTUAL,
 INDEX(y)
) ENGINE=InnoDB;
 
SHOW CREATE TABLE t1;
SELECT * FROM t1 WHERE y BETWEEN 2012 AND 2016 FOR UPDATE;
INSERT INTO t1 (i) VALUES (1),(2);
SELECT * FROM t1 WHERE y BETWEEN 2012 AND 2016 FOR UPDATE;
DROP TABLE t1;

#
# MDEV-11726: Server crashes in mach_read_from_n_little_endian
#

CREATE TABLE t1 ( 
 y YEAR NULL,
 i SMALLINT NULL,
 b BLOB NULL,
 vi SMALLINT AS (i) VIRTUAL,
 INDEX(y)
) ENGINE=InnoDB;
 
SHOW CREATE TABLE t1;
SELECT * FROM t1 WHERE y BETWEEN 2012 AND 2016 FOR UPDATE;
INSERT INTO t1 (i) VALUES (1),(2);
SELECT * FROM t1 WHERE y BETWEEN 2012 AND 2016 FOR UPDATE;
DROP TABLE t1;

--echo #
--echo # MDEV-23632 ALTER TABLE...ADD KEY creates corrupted index on virtual column
--echo #

CREATE TABLE t1(a INT PRIMARY KEY, b INT, g INT GENERATED ALWAYS AS(b)VIRTUAL) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1,1,default);
ALTER TABLE t1 ADD COLUMN c INT;
ALTER TABLE t1 ADD KEY(g);
CHECK TABLE t1;
SELECT g FROM t1 FORCE INDEX (g);
DROP TABLE t1;

CREATE TABLE t1(a INT, b INT, g INT GENERATED ALWAYS AS(b)VIRTUAL) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1,1,default);
ALTER TABLE t1 ADD COLUMN c INT PRIMARY KEY; # Triggers `new_clustered`
ALTER TABLE t1 ADD KEY(g);
CHECK TABLE t1;
SELECT g FROM t1 FORCE INDEX (g);
DROP TABLE t1;
