3350
MySQLERRORNotableDDL / IndexesHIGH confidence

Functional index cannot reference AUTO_INCREMENT column

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 ((id * 2)); -- id is AUTO_INCREMENT

expected output

ERROR 3350 (HY000): Functional index cannot refer to an auto-increment column.

Fix

Use a generated column

Use a generated column
ALTER TABLE t ADD COLUMN id2 INT GENERATED ALWAYS AS (id * 2) VIRTUAL; CREATE INDEX idx ON t (id2);

Why this works

Generated columns can reference AUTO_INCREMENT columns and be indexed.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3350 ER_FUNCTIONAL_INDEX_REF_AUTO_INCREMENT

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MySQL errors