Skip to Content
MySQL 8 Cookbook
book

MySQL 8 Cookbook

by Karthik Appigatla
January 2018
Intermediate to advanced
446 pages
12h 57m
English
Packt Publishing
Content preview from MySQL 8 Cookbook

Index on generated columns

An index cannot be used on a column wrapped in a function. Suppose you add an index on hire_date:

mysql> ALTER TABLE employees ADD INDEX(hire_date);Query OK, 0 rows affected (0.93 sec)Records: 0  Duplicates: 0  Warnings: 0

The index on hire_date can be used for queries having hire_date in the WHERE clause:

mysql> EXPLAIN SELECT COUNT(*) FROM employees WHERE hire_date>'2000-01-01'\G*************************** 1. row ***************************           id: 1  select_type: SIMPLE        table: employees   partitions: NULL         type: rangepossible_keys: hire_date          key: hire_date      key_len: 3          ref: NULL         rows: 14     filtered: 100.00        Extra: Using where; Using index1 row in set, 1 warning (0.00 sec)

Instead, if you put hire_date inside a function, MySQL ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

MySQL Cookbook

MySQL Cookbook

Paul DuBois
Advanced MySQL 8

Advanced MySQL 8

Eric Vanier, Birju Shah, Tejaswi Malepati

Publisher Resources

ISBN: 9781788395809Other