Repository navigation
Open
Description
Description
MySQL 8.0.13+ supports unique functional indexes. The canonical use case is a case-insensitive unique email/username column:
CREATE TABLE users (
id INT PRIMARY KEY,
email VARCHAR(100),
UNIQUE KEY uk ((LOWER(email))) -- MySQL 8.0: works
);In MySQL this rejects [email protected] when [email protected] already exists. MatrixOne supports ordinary (non-unique) functional indexes — both inline KEY ((expr)) and CREATE INDEX ... ((expr)) work, the plan shows Index Table Scan, and results are correct — but any attempt at a UNIQUE variant fails:
| statement | MySQL 8.0 | MatrixOne |
|---|---|---|
CREATE TABLE t(... UNIQUE KEY uk((LOWER(email)))) |
works | internal error: unsupported index which using expression as keypart |
CREATE UNIQUE INDEX uq_idx ON t((LOWER(email))); |
works | not supported: unique or special functional indexes |
Two additional observations:
- The DDL-time failure is an internal error (20101) exposed to the client, not a clean syntax/feature message.
- The failed
CREATE TABLE ... UNIQUE KEY uk(...)leaves no orphan table — good. But note the error surfaces only at CREATE TABLE time; there is no diagnostic pointing at the unsupported key part.
Reproduction
-- inline unique functional key
CREATE TABLE fidx_uq (
id INT PRIMARY KEY,
email VARCHAR(50),
UNIQUE KEY uk ((LOWER(email)))
);
-- MO: ERROR 20101 (HY000): internal error: unsupported index which using expression as keypart
-- MySQL 8.0: Query OK
-- standalone form on an existing table
CREATE TABLE fidx_uq2 (id INT PRIMARY KEY, email VARCHAR(50));
CREATE UNIQUE INDEX uq_idx ON fidx_uq2 ((LOWER(email)));
-- MO: ERROR 20105 (HY000): not supported: unique or special functional indexes
-- MySQL 8.0: Query OKImpact
- Case-insensitive unique constraints (emails, usernames, slugs) require either a stored generated column workaround (extra column + unique index on it) or application-level dedup checks.
- Applications migrated from MySQL 8.0 using unique expression indexes fail at DDL time with an "internal error", which suggests a crash-worthy defect rather than a documented feature gap.
Expected behavior
Either full support for unique functional indexes (matching MySQL 8.0.13+), or at minimum a clear, documented "not supported" error instead of internal error. If truly unsupported, this should also be tracked in the MySQL-compat matrix.
Activity