Which type of query does MySQL hate?

Source: Internet
Author: User
Tags mysql query optimization

(I) any query is annoying.

As long as the query and MySQL are annoying, the fastest way to execute the query is not to execute

Cache is king, such as Redis or memcache

(Ii) Minimum query result set

Try to query based on the primary key or secondary index, and avoid returning the table by overwriting the index to save IO

For example:

Select col1 from table where primary_key_column = something;

(3) query with JOINS

Use appropriate anti-paradigm to avoid JOIN

For example:

SELECT t2.value FROM t2 JOIN t1 ON (t1.id = t2.tid) WHERE t1.orderdate = NOW ()

You can extract the orderdate column in t1 and place it in t2.

SELECT t2.value FROM t2 WHERE t2.orderdate = NOW ()

(Iv) Aggregate Query is the most annoying

Periodic pre-load summary tables to avoid real-time online Aggregate Queries

Using INSERT... on duplicate key update is helpful.

MySQL queries the first n records

MySQL query optimization: LIMIT 1 avoids full table Scan

MySQL query optimization: Use subqueries instead of non-primary key connection queries

MySQL Query Optimization-Show command

MySQL query does not use index summary

Related Article

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.