MySQL sort buffer and join buffer learning notes

Source: Internet
Author: User
Tags join

Related Parameters View commands

SELECT @ @join_buffer_size;

SELECT @ @sort_buffer_size;

==========================================================================================

Join_buffer_size

The buffer used when our join is All,index,rang or index_merge.

This join is actually called a full join.

Virtually every table participating in a join requires a join buffer.

So when the join appears, it's at least 2.

This is only a maximum of 4G before the mysql5.1.23 version, but starting with the 5.1.23 version, the 64 on the platform beyond Windows can exceed the 4GB limit.

The system defaults to 128KB.

==========================================================================================

Sort_buffer_size

Sort buffer is the buffer used when sorting data in the system.

The sort buffer is also for a single thread, so multiple sort buffer appears in the system when multiple threads are sorted at the same time.

We can generally increase the processing performance of order by or group by by increasing the size of the sort buffer.

The system defaults to 2MB, the maximum limit is the same as the join buffer.

==========================================================================================

Optimization recommendations

If the join statement is rarely present in the application, you may not care too much about the setting size of the Join_buffer_size parameter.

If the join statement is not very small, personal suggestions can be appropriately increased join_buffer_size to 1MB or so, if sufficient memory can be set to 2MB.

For Sort_buffer_size, a general setting of 2-4MB can meet the needs of most applications.

Of course, if the order in the application is relatively large. You can also continue to increase the settings for the sort buffer size when there is sufficient memory but not a particularly large amount of concurrency.

The last thing to note is that each thread creates its own independent buffer rather than the entire system share, so the set value is too low for the system to be in memory.

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.