Common hint in MySQL

Source: Internet
Author: User

Force index of Forces index
SELECT * from TABLE1 (FIELD1) ...
The above SQL statements use only the indexes built on FIELD1, not the indexes on other fields.
Ignore index IGNORE index
SELECT * from TABLE1 IGNORE index (FIELD1, FIELD2) ... in the above SQL statement, the indexes on FIELD1 and FIELD2 in the TABLE1 table are not used.
close query buffering sql_no_cache
SELECT sql_no_cache field1, field2 from TABLE1;
There are some SQL statements that need to query the data in real time, or not often (maybe one or two times a day), so you need to turn the buffer off, regardless of whether the SQL statement is executed, the server does not look in the buffer and executes it every time.
SELECT sql_calhe * from TABLE1;
If the Query_cache_type in My.ini is set to 2, then query buffering is used only after Sql_cache is used.

Priority Operation High_priority
High_priority can be used in select and insert operations to let MySQL know that this operation takes precedence.
SELECT high_priority * from TABLE1;
Force Connection Order Straight_join
SELECT TABLE1. FIELD1, TABLE2. FIELD2 from TABLE1 straight_join TABLE2 WHERE ...
The SQL statement above shows that by Straight_join forcing MySQL to join the table in TABLE1, TABLE2 order. You can determine the connection order by Straight_join If you think it is more efficient to connect in your own order than the MySQL recommended sequence.
Forcing the use of temporary tables Sql_buffer_result
SELECT Sql_buffer_result * from TABLE1 WHERE ...
When the data in the result set of our query is relatively long, we can pass the Sql_buffer_ The result. Option forces the results set to be placed in the staging table so that the MySQL table lock can be released quickly (so that other SQL statements can query the records) and can provide the client with a large recordset for a long time.

Common hint in MySQL

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.