Summary of select and where clause optimization in mysql
This article brings you a summary of the optimization of select and where clauses in mysql. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Database optimization:
1. Optimization can be performed at the level of a single SQL statement, the entire application, a single database server, or multiple networked database servers
#2. Database performance depends on several factors at the database level, such as tables, queries and configuration settings
3. Optimize at the database level, optimize at the hardware level, balance portability and performance
4. Appropriate structure, appropriate data type; applications that perform frequent updates with a large number of tables (few columns); applications that analyze large amounts of data with a small number of tables (multiple columns); choose appropriate storage engines and indexes;
5. Compression is applicable Various workloads for InnoDB tables, as well as read-only MyISAM tables
6. Choose an appropriate locking strategy; the InnoDB storage engine can handle most locking issues
7. The main memory areas configured are the InnoDB buffer pool and MyISAM Key cache.
8. Optimize the select statement. This technique is also applicable to other delete statements with where. Set indexes on the columns of the where clause; indexes are especially important for referencing multiple columns such as joins and foreign keys.
select where clause optimization:
1. Adjust the structure of the query, such as function calls, only call them once for each row in the result set, and for each row in the table Called only once
2. Reduce the number of full table scans in queries
3. Regularly use the ANALYZE TABLE statement to keep table statistics up-to-date
4. Understand the tuning techniques of the storage engine specific to each table , indexing technology and configuration parameters
5. Optimize single-query transactions for InnoDB tables
6. Investigate the internal details of a specific query by reading the EXPLAIN plan and adjusting indexes, WHERE clauses, join clauses, etc.
7. Adjust the size and properties of the memory area used by MySQL for caching. By effectively using the InnoDB buffer pool, MyISAM key cache and MySQL query cache
8.where condition, remove unnecessary parentheses, constant folding, constant condition removal, reduce unnecessary logic
9.Used by the index Constant expressions are only calculated once
10.count(*) is queried directly from the table information; when there is only one table, the same is true for not null expressions
11.If you do not use GROUP BY or aggregate function (COUNT (), MIN (), etc.), HAVING will be merged with WHERE
12. Constant table, only one row or empty table; where clause acts on primary key or unique index
13. If ORDER BY and GROUP BY If all the columns in the clause come from the same table, the table will be preferred when connecting
14. If the order by clause and the group by clause are different, or come from different tables, a temporary table will be created
15. If you use the SQL_SMALL_RESULT modifier, MySQL will use an in-memory temporary table
16. MySQL can just read rows from the index without even consulting the data file
17. Before outputting each row, a jump will Pass rows that do not match the HAVING clause
The following table is used as a constant table:
1 2 3 |
|
The following query runs very fast:
1 2 3 4 5 6 7 8 |
|
1 2 3 4 |
|
The following query uses the index to retrieve data in sorted order, no separate sorting is required
1 2 3 4 |
|
The above is the detailed content of Summary of select and where clause optimization in mysql. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics





You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting
