MySQL SQL optimization

Source: Internet
Author: User

Record some experience, mainly the conclusion. Build the search and so on will not write, the Earth people know.

1. Comparison of 2 joins

SELECT * FROM (SELECT * from A where is >) inner JOIN (SELECT * from B where grade > 3) TB on a.b_id = Tb.id;sel ECT * FROM (SELECT * from A where >) inner join B on a.b_id = b.ID and B.grade > 3;

When the ID field of B is the primary key or index, if the amount of data reaches tens, the second may be more than 10 times times faster than the first SQL because the first SQL terabyte is not indexed.

2. JDBC connects MySQL to insert data and uses BULK insert to increase performance by more than 8 times times. There are two points to pay attention to:

(1) the database connection needs to be added "Rewritebatchedstatements=true", otherwise JDBC will not really use BULK INSERT.

(2) If MySQL has a master-slave, note that the number of bulk inserts not too much, to prevent failure.

3. Observe the SQL executed by MySQL

With tail-f view, the SQL execution log file path is general_log_file defined in the my.cnf file.

4. Using explain

See http://database.51cto.com/art/200912/168453.htm

MySQL SQL optimization

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.