Skip to content

Latest commit

 

History

History
24 lines (19 loc) · 1.15 KB

mysql-do-nots.md

File metadata and controls

24 lines (19 loc) · 1.15 KB

MySQL Dont's - performance

1. No function in where (column_name)

# Never use a function for the column name in where 
# e.g. 
select * from donors where upper(last_name) like 'Willia%'

Why ?

  • Not index can be used
# Not filtering possible by indx -> possible_keys -> NULL 
 explain select last_name from donors where upper(last_name) like 'WILLI%';
+----+-------------+--------+------------+-------+---------------+-------------------+---------+------+--------+----------+--------------------------+
| id | select_type | table  | partitions | type  | possible_keys | key               | key_len | ref  | rows   | filtered | Extra                    |
+----+-------------+--------+------------+-------+---------------+-------------------+---------+------+--------+----------+--------------------------+
|  1 | SIMPLE      | donors | NULL       | index | NULL          | donors_donor_info | 687     | NULL | 701948 |   100.00 | Using where; Using index |
+----+-------------+--------+------------+-------+---------------+-------------------+---------+------+--------+----------+--------------------------+
1 row in set, 1 warning (0.00 sec)