O'Reilly logo

MySQL 8 Cookbook by Karthik Appigatla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using EXPLAIN

The explain plan gives information on how the optimizer is going to execute the query. You just need to prefix the EXPLAIN keyword to the query:

mysql> EXPLAIN SELECT dept_name FROM dept_emp JOIN employees ON dept_emp.emp_no=employees.emp_no JOIN departments ON departments.dept_no=dept_emp.dept_no WHERE employees.first_name='Aamer'\G*************************** 1. row ***************************           id: 1  select_type: SIMPLE        table: employees   partitions: NULL         type: refpossible_keys: PRIMARY,name          key: name      key_len: 58          ref: const         rows: 228     filtered: 100.00        Extra: Using index*************************** 2. row ***************************           id: 1  select_type: SIMPLE        table: dept_emp   partitions: NULL         type: refpossible_keys: PRIMARY,dept_no ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required