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 for connection

You can run the explain plan for an already-running session. You need to specify the connection ID: To get connection ID, execute:

mysql> SELECT CONNECTION_ID();+-----------------+| CONNECTION_ID() |+-----------------+|             778 |+-----------------+1 row in set (0.00 sec)
mysql> EXPLAIN FORMAT=JSON FOR CONNECTION 778\G*************************** 1. row ***************************EXPLAIN: {  "query_block": {    "select_id": 1,    "cost_info": {      "query_cost": "881.04"    },    "nested_loop": [      {        "table": {          "table_name": "employees",          "access_type": "index",          "possible_keys": [            "PRIMARY"          ],          "key": "name",          "used_key_parts": [            "first_name",            "last_name"          ],          "key_length": "124",          "rows_examined_per_scan": 1,          "rows_produced_per_join": 1,

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