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

MySQL implementation of lastInfdexOf function example

Sometimes MySQL needs to use a function similar t...

MySQL SHOW PROCESSLIST assists in the entire process of troubleshooting

1. SHOW PROCESSLIST command SHOW PROCESSLIST show...

Detailed explanation of chmod command usage in Linux

chmod Command Syntax This is the correct syntax w...

Detailed explanation of the basic functions and usage of MySQL foreign keys

This article uses examples to illustrate the basi...

Vue implements an example of pulling down and scrolling to load data

Table of contents Step 1: Installation Step 2: Ci...

How to install a virtual machine with Windows services on Mac

1. Download the virtual machine Official download...

Example of using mycat to implement MySQL database read-write separation

What is MyCAT A completely open source large data...

Linux installation Redis implementation process and error solution

I installed redis today and some errors occurred ...

How to calculate the frame rate FPS of web animations

Table of contents Standards for smooth animation ...

TCP performance tuning implementation principle and process analysis

Three-way handshake phase Number of retries for c...

Win10 + Ubuntu20.04 LTS dual system boot interface beautification

Effect display The built-in boot interface is too...

Add a startup method to Linux (service/script)

Configuration file that needs to be loaded when t...

A simple method to be compatible with IE6's min-width and min-height

If a website is widescreen, you drag the browser ...