Mysqlunionall efficiency problems

Source: Internet
Author: User
Mysqlunionall efficiency I have several tables with the same structure and need to perform join table queries. I use the following statement select & nbsp; sum (cnt) & nbsp; from & nbsp; (select & nbsp; count (*) & nbsp; as & nbsp; cnt & nbsp; from & nbsp; t1 & nbsp; w mysql union all efficiency issues

I have several tables with the same structure and need to perform join table query. I use the following statement:

Select sum (cnt) from (select count (*) as cnt from t1 where a> 100 union all select...) as t;
The sum of this sentence is fast.

Select * from t1 where a> 100 union all select * from t2 where a> 100 union all select * from t3 where a> 100 order by B desc limit;
This sentence seems to be very inefficient. it takes a long time to come out.

How to optimize it? thank you.


------ Solution --------------------
In the second sentence, order by B desc limit is estimated to affect the vertex. remove the vertex and try again.
------ Solution --------------------
In the union structure, only one order is allowed (except in subqueries)
Your writing method is obviously unreasonable, or it is outdated (because you have done manual table sharding and the segmentation is unreasonable)
Currently, mysql provides the partition function, as long as the setting is reasonable and the speed of a single small table is equal (although it is also cut into multiple data files)

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.