3358
MySQLERRORNotableDDL / IndexesHIGH confidence
Functional index key column has an incorrect type
Production Risk
Low — DDL fails; no index is created.
How to reproduce
trigger — this will error
trigger — this will error
CREATE INDEX idx ON t ((some_expr_returning_blob));
expected output
ERROR 3358 (HY000): The used key column has incorrect type for a functional index.
Fix
Cast to a scalar type
Cast to a scalar type
CREATE INDEX idx ON t ((CAST(some_json_col AS CHAR(100))));
Why this works
Casting to a bounded character type produces an indexable key.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 3358 ER_WRONG_KEY_COLUMN_FUNCTIONAL_INDEX
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev