Description:
Creating the index directly works, but the operation fails when wrapped in an IF() function, and the resulting error message is not correct or is misleading.
mysql> CREATE UNIQUE INDEX i1 ON t0(c3);
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> DROP INDEX i1 ON t0;
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> CREATE UNIQUE INDEX i1 ON t0(c2);
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> DROP INDEX i1 ON t0;
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> CREATE UNIQUE INDEX i1 ON t0((IF(NULL, c3, c2)));
ERROR 1170 (42000): BLOB/TEXT column '!hidden!i1!0!0' used in key specification without a key length
How to repeat:
DROP TABLE IF EXISTS `t0`;
CREATE TABLE `t0` (
`c0` decimal(10,0) DEFAULT NULL,
`c1` tinyint(1) NOT NULL ,
`c2` tinyint(1) DEFAULT NULL,
`c3` float(36,25) unsigned zerofill DEFAULT NULL ,
`c4` blob,
`c5` float unsigned zerofill DEFAULT NULL ,
`c6` bigint(90) unsigned zerofill DEFAULT NULL ,
`c7` smallint(14) unsigned zerofill DEFAULT NULL ,
`c8` tinyint(236) unsigned zerofill DEFAULT NULL,
`c9` mediumblob ,
PRIMARY KEY (`c1`),
KEY `i0` (`c1`,`c2`,`c4`(4),`c6`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
CREATE UNIQUE INDEX i1 ON t0(c3);
DROP INDEX i1 ON t0;
CREATE UNIQUE INDEX i1 ON t0(c2);
DROP INDEX i1 ON t0;
CREATE UNIQUE INDEX i1 ON t0((IF(NULL, c3, c2)));