Basic tutorial on using explain statement in MySQL

Basic tutorial on using explain statement in MySQL

1. Overview

In MySQL, we can use slow query logs or show processlist commands to locate SQL statements that take a long time to execute. After that, we can use EXPLAIN or DESC commands to obtain information about how MySQL executes SELECT statements, including how tables are connected and the order in which they are connected during the execution of SELECT statements.

1. Explain statement test

explain+select statement is the usage of explain command

2. Description of each column in the explain result

Below, we will explain these columns one by one.

2. Explain ID column

1. Environmental preparation


2. Detailed explanation of the id column in explain

The id field is the serial number of the select query, which is a set of numbers that represents the order in which the select clauses are executed or the tables are operated in the query. There are three id situations: (1) The same id means the order of loading tables is from top to bottom.

(2) id The larger the id value, the higher the priority and the earlier it is executed.

(3) Some ids are the same, while others are different and exist at the same time. Items with the same id can be considered as a group and executed sequentially from top to bottom. Among all groups, the larger the id value, the higher the priority and the earlier it is executed.

3. select_type column of explain

1. select_type

2.

SIMPLE

3. PRIMARY, SUBQUERY

4. DERIVED

5. UNION, UNION RESULT

IV. Explain table and type columns

1. Table columns

The table column shows which table the row of data belongs to.

2. Type column

The type column shows the access type.

3. Example

(1) NULL

(2) system

(3) const

(4) eq_ref

(5) ref

(6) index

(7) ALL

5. Explain key, rows, and extra columns

1. key


2. rows

Number of scan lines

If there is an index, only one row is scanned

3. Extra

Summarize

This is the end of this article about the basic usage tutorial of explain statement in MySQL. For more relevant content on the use of explain in MySQL, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • MySQL performance analysis and explain usage instructions
  • Detailed explanation of the use of mysql explain (analysis index)
  • How to use explain to query SQL execution plan in MySql
  • MySQL enables slow query (introduction to using EXPLAIN SQL statement)
  • Usage of mysql explain (use explain to optimize query statements)
  • Introduction to the use of explain, a MySQL optimization tool
  • Basic usage analysis of Explain, a magical tool for MySQL performance optimization
  • Mysql experiment: using explain to analyze the trend of indexes
  • Use and analysis of Mysql Explain command
  • Detailed explanation of MySQL Explain

<<:  Web page production TD can also overflow hidden display

>>:  Solve the problem of docker pull image error

Recommend

Detailed explanation of Vue save automatic formatting line break

I searched for many ways to change it online but ...

Build a file management system step by step with nginx+FastDFS

Table of contents 1. Introduction to FastDFS 1. I...

Several ways to implement CSS height changing with width ratio

[Solution 1: padding implementation] principle: I...

Causes and solutions for slow MySQL queries

There are many reasons for slow query speed, the ...

Let's talk briefly about the changes in setup in vue3.0 sfc

Table of contents Preface Standard sfc writing me...

MySQL 5.7.11 zip installation and configuration method graphic tutorial

1. Download the MySQL 5.7.11 zip installation pac...

Detailed explanation of MySQL multi-table join query

Table of contents Multi-table join query Inner Jo...

Detailed explanation of the execution plan explain command example in MySQL

Preface The explain command is the primary way to...

How to use rem adaptation in Vue

1. Development environment vue 2. Computer system...

A brief talk about JavaScript Sandbox

Preface: Speaking of sandboxes, our minds may ref...

Pessimistic locking and optimistic locking in MySQL

In relational databases, pessimistic locking and ...

Notes on Using Textarea

Why mention textarea specifically? Because the tex...

CentOS system rpm installation and configuration of Nginx

Table of contents CentOS rpm installation and con...