MySQL partition table to ordinary table Huzhuan

Due to the recent implementation of SQL always someone complaining about slow data migration later, after viewing the original cause of the problem partition. According to the original partition set monthly RANGE partition,

See this diagram and then perhaps someone will find the problem .......

Business inquiries SQL:

From the point of view SQL execution plan is really gone partition, but why it did not hit the index, there are joint index (idx_reportDate_groupID_shopID_saasOrderKey) in in Figure 1

 

## ideas to solve the problem

 

1, if forced to take the specified index, it is really fast, but also the number of lines scanned sweep

However, due to too much trouble to modify business, we were asked to libraries and other unified index, regardless of .... continue to find problems before ......

 

2 to solve the problem:

 

   Speculation may be table statistics and debris caused by the dump restore operation, the result is still the same did not solve the problem ......

 

3 to solve the problem:

 

  SQL query to No. 1 on the 10th of relatively long period of time span, is it optimizer theoretical problem ..... do not know much .... continue to find problems

 

  First SQL query simplify operations such as select * from .... operation

It found that the results were good, then modify the query time. SQL queries by business look

Found the problem, should logically be in P27 partition, how to sweep so many partitions, which can be defined in Figure 1 and the partition has a relationship defined partition out of the question, is this really to find the problem.

 

Begin to solve the problem:

 

At present 3000W should be thinking about how to reconstruct the partition table, but can not delete the original data to be retained

 

method 1:

 

For small ALTER TABLE perform operations: alter table table_name remove partitioning; ## removing the partition, the lock table

 

Pt-osc can use the online tool to remove the partition, does not affect business

 

pt-online-schema-change -u load_data -h 192.168.21.113 -p root123 -P 3306 --alter=" REMOVE PARTITIONING" D=test,t=tbl_saas_order_food --charset=utf8 --no-version-check  --statistics --critical-load="Threads_running:200" --max-load="Threads_running=25" --print --execute

 

发现一移除分区查询瞬间变快

图索引刚加,在没这个索引 也可使用令一索引

 

重构分区:

 

小表自行alter table tabe_name PARTITION BY range(sid)(PARTITION p1512 VALUES LESS THAN (20160101),

 

 PARTITION p1601 VALUES LESS THAN (20160201),.........,PARTITION p888666 VALUES LESS THAN MAXVALUE)

 

大表:PT-OSC,如图

重构分区后,执行计划

其他验证,是否指定分区:

发布了447 篇原创文章 · 获赞 71 · 访问量 40万+

Guess you like

Origin blog.csdn.net/w892824196/article/details/103976958