# Functional Indexes in MySQL

## Metadata
- Author: [[Scott Stroz]]
- Full Title: Functional Indexes in MySQL
- Category: #articles
- Summary: MySQL 8.0.13 introduced functional indexes that speed up queries using expressions in the WHERE clause. These indexes work by indexing the result of a function or expression, improving performance without rewriting queries. However, there are rules and limitations to follow when creating and using functional indexes.
- URL: https://blogs.oracle.com/mysql/functional-indexes-in-mysql
## Highlights
- Functional indexes can increase query performance without having to rewrite the query to address any bottlenecks. ([View Highlight](https://read.readwise.io/read/01m2p1v97x7mvvzcdcvq2rh756))
- • Expressions MUST be contained in parentheses to differentiate them from columns.
• `INDEX((col1 + col2))` vs `INDEX( col1, col2)`
• We can create an index that has functional and non-functional definitions.
• `INDEX((col1 + col2), col1)`
• Functional index definitions cannot contain only column names.
• `INDEX ((col1), (col2))` will throw an error.
• Functional index definitions are not allowed in foreign key columns.
• The index will only be used when a query uses the same expression.
• `select count(*) from test_data where col1 - col2 = 0` will NOT use the index we created.
• We would need to create a new index using the expression `(col1-col2)`. ([View Highlight](https://read.readwise.io/read/01m2p2c417wwt9dgaae0yy3vsx))
- As we have shown, functional indexes can help performance in queries that use expressions in the `WHERE` clause ([View Highlight](https://read.readwise.io/read/01m2p2ck27zye2j8vj93hqvdeq))