Explanation of the execution priority of mySQL keywords

Explanation of the execution priority of mySQL keywords

As shown below:

from table

where condition

group by field

Form virtual tables and fields, aggregate and add fields

having filter data

distinct

order by field asc,desc

limit limit number of entries

Select List Records

First, the data is loaded from the table into memory according to the where constraint, so the where condition acts before the data, and then grouped according to the field, forming a virtual table in memory containing the field.

If there is an aggregate function at this time, the aggregate function is executed first, and the aggregate function field is also added to the virtual table. Then the having record filter is performed. After the filtering is completed, the data is deduplicated, sorted, restricted, and other operations are performed before display.

Additional knowledge: The execution order of mysql where conditions and is from left to right

When I was working on this function before, I encrypted the three conditions through md5 to get a string field unique_key, and set this field as the unique index. I hope to use this unique index when searching, without having to search for the three conditions separately. At the same time, I used the replace method to ensure that if the data is updated under the same three conditions, there will be only one record in the database.

Later I found that the list query must open these three conditions, so I had to put the unique_key to the left of the where condition and, and the efficiency of filtering by unique_key would not be bad.

You should consider all aspects of MySQL optimization when writing.

The above explanation of the execution priority of mySQL keywords is all I want to share with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • How to optimize MySQL index function based on Explain keyword
  • Detailed explanation of mysql execution plan id is empty (UNION keyword)
  • jq.ajax+php+mysql to implement keyword fuzzy query (example explanation)
  • Detailed Introduction to the MySQL Keyword Distinct
  • MySql multi-condition query statement with OR keyword

<<:  Example code for element multiple tables to achieve synchronous scrolling

>>:  Briefly describe how to install Tomcat image and deploy web project in Docker

Recommend

How to isolate users in docker containers

In the previous article "Understanding UID a...

Solve the problem of insufficient docker disk space

After the server where Docker is located has been...

WeChat Mini Programs Achieve Seamless Scrolling

This article example shares the specific code for...

React introduces antd-mobile+postcss to build mobile terminal

Install antd-mobile Global import npm install ant...

Detailed graphic tutorial on installing centos7 virtual machine in Virtualbox

1. Download centos7 Download address: https://mir...

Detailed explanation of the payment function code of the Vue project

1. Alipay method: Alipay method: Click Alipay to ...

Solution to the problem of data loss when using Replace operation in MySQL

Preface The company's developers used the rep...

Solve the problem of blank gap at the bottom of Img picture

When working on a recent project, I found that th...

What is the function and writing order of the a tag pseudo class

The role of the a tag pseudo-class: ":link&qu...

How to use yum to configure lnmp environment in CentOS7.6 system

1. Installation version details Server: MariaDB S...

How to directly reference vue and element-ui in html

The code looks like this: <!DOCTYPE html> &...

Detailed explanation of CSS sticky positioning position: sticky problem pit

Preface: position:sticky is a new attribute of CS...