Tags: subquery digital compilation full table scan large efficient list over technology1, do not use sequential lookup, because the order lookup is slow, through the characteristics of the specific data structure to improve the query speed, this data structure is can be understood as an index. 2, the index is generally stored on disk in the form of files, index retrieval requires disk I/O operations, in order to minimize disk I/O. The disk is often
query results will also tell you how your index primary key is being leveraged, how your data tables are searched and sorted ... Wait, wait. Pick one of your SELECT statements (it is recommended to pick one of the most complex, multi-table joins) and add the keyword explain to the front. You can use phpMyAdmin to do this. Then, you'll see a table. In the following example, we forget to add the group_id index and have a table join: When we index the g
article system pagination display, the general query is this:
Copy Code code as follows:
SELECT ID, title, content from article order by created DESC LIMIT 10000, 10;
Usually such queries build the index in the Created field (where the ID is the primary key), but when the limit is very large, query efficiency is still very low, change the query:
Copy Code code as follows:
SELECT ID, title, content from article
INNER
Mysql Performance Monitoring related bitsCN.com
Mysql Performance Monitoring
1. obtain the total number of processes under the mysql User
II. host performance status
III. CPU usage
IV. disk I/O volume
5. swap inbound/outbound [m
, join paging mode The code below copies the code select * from ' content ' as T1 JOIN (SELECT ID from ' content ' ORDER by id desc LIMIT.) ( $page-1) * $pagesize. ", 1) as T2 WHERE t1.id After my testing, the efficiency of join paging and sub-query paging is basically on one level, and the time consumed is basically the same. Explain SQL statements: The code be
information data of active users; Personalized and customized information data for active users; Quasi-real-time statistical information data; Some other frequently accessed but less-changed data; 3 Query The effect of statements on system performance Requirements: Take out a group (assuming ID 1) under the user number (ID), user nickname (Nick_name), and follow the time to join the group (user_group.gmt_c
the most complex, multiple table joins) and add the keyword explain to the front. You can use phpMyAdmin to do this. Then, you'll see a table. In the following example, we forget to add the group_id index and have a table join:
When we index the group_id field:
As we can see, the previous result shows a search of 7883 rows, and the last one searches only 9 and 16 rows of two tables. Viewing the Rows column allows us to identify potential
information data for active users; Quasi-real-time statistical information data; Some other frequently accessed but less-changed data; 3 Query The effect of statements on system performance Requirements: Take out a group (assuming ID 1) under the user number (ID), user nickname (Nick_name), and follow the time to join the group (user_group.gmt_create) in reverse order, remove the first 20. Solution One: SE
Abstract: This article describes how to optimize SQL queries. You can manually use the EXPLAIN statement to check the efficiency of SQL queries. In addition, some principles for optimizing SQL statements are described, mainly about how to optimize SQL statements when retrieving records and loading data.
Use the EXPLAIN statement to check SQL statements
When you put the keyword "EXPLAIN" in front of a SELECT statement, MySQL explains how it will proce
follows:
Mysql> explain select store_id, film_id FROM sakila. inventory \ G
(2) for example, when the page is displayed in the article system, the general query is as follows:
The code is as follows:
SELECT id, title, content FROM article order by created desc limit 10000, 10;
In general, the index will be created in the created field (where id is the primary key), but when the LIMIT offset is large, the query efficiency is still very low, change th
tell you how your index primary key is being leveraged, how your data tables are searched and sorted ... Wait, wait. Pick one of your SELECT statements (it is recommended to pick one of the most complex, multi-table joins) and add the keyword explain to the front. You can use it phpmyadmin to do it. Then, you'll see a table. In the following example, we forget to add an group_id index and have a table join: When we group_id index a field: As we can
files after all the associations have finished. If so, the extra field in the explain result will have a using temporary; Using Filesort. If there is a limit in the query, the limit is also applied after the sort. So even if you need to return fewer rows, the temporary table and the amount of data that needs to be sorted are still very large.mysql5.6 has made a number of important improvements here. When you only need to return partial sorting results, for example, using the limit clause,
MySQL performance optimization and mysql Optimization
How to extract a random entry from a data table in MySQL, while ensuring the highest efficiency.
Method 1This is the most primitive and intuitive syntax, as shown below:SELECT * FROM foo order by rand () LIMIT 1This method is feasible when the data volume in the dat
group_id index and have a table join:
When we index the group_id field:
As we can see, the previous result shows a search of 7883 rows, and the last one searches only 9 and 16 rows of two tables. Viewing the Rows column allows us to identify potential performance issues.
3. Use LIMIT 1 when only one row of data is used
There are times when you query the table and you already know that there will on
-text index or make an index yourself (say, search for keywords or tags, etc.)5. Use a fairly typed example in the Join table and index itIf your application has many join queries, you should confirm that the fields of join in two tables are indexed. In this way, MySQL internally initiates the mechanism for you to opti
for keywords or tags, etc.)5. Use a fairly typed example in the Join table and index itIf your application has many join queries, you should confirm that the fields of join in two tables are indexed. In this way, MySQL internally initiates the mechanism for you to optimize the SQL statement for join.Also, the fields t
the Join table and index itIf your application has many join queries, you should confirm that the fields of join in two tables are indexed. In this way, MySQL internally initiates the mechanism for you to optimize the SQL statement for join.Also, the fields that are used for join
Tags: today enum thread NBU Show course Str LTE roundBest 20 + Experience sharing for MySQL performance optimizationMySQL the best over 20 experience sharing for performance optimization ....... ............... ....................... ........ 1 1. Optimize your query for the query cache ....... ..... ................ ....... ..... ....................... 2 2. EX
numeric data, and numeric data is processed much faster than text type. In this way, we can improve the performance of the database.
2, use the connection (join) to replace the subquery (sub-queries)
MySQL supports SQL subquery starting with 4.1. This technique can use a
latter will be more efficient than the previous one. (Note that the first one is select *, and the second is select 1)//Inefficient: $r=mysql_query ("SELECT * from User WHERECountry= ' China'"); if(Mysql_num_rows ($R)> 0) { // ... } //Efficient: $r=mysql_query ("SELECT 1 from User WHERECountry= ' China'LIMIT1"); if(Mysql_num_rows ($R)> 0) { // ... }4. Jianjian Index for search wordsThe index does not necessarily give the primary key or the unique field. If you have a field in your table
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.