# Region Merge Slow (B)


![left](./student-guide/diagram/25-region-merge-solution-01-01.png)

------------------------------------------------------------

Possible causes and solutions
When a region is empty in a cluster, it is usually accompanied by a large amount of data deletion in the cluster, such as Drop, Truncate Table, and Delete.

- Adjust Region Merge Schedue Limit 
Slow Region Merge is also likely to be limited by a limit (Region Merge is limited to both merge-schedule-limit and region-schedule-limit), or competition with other schedulers, and the processing method will not be discussed further.

- Adjust max-merge-region-size, max-merge-region-keys, and patrol-region-interval
If we have statistically learned that there are a large number of empty regions in the system, we can speed up the merge by adjusting the max-merge-region-size and max-merge-region-keys to smaller values. This is because the Merge process involves migration replica, so the smaller the Merge Region, the faster it will be. If the Merge Operator is already generating hundreds of opms and you want to speed it up even further, you can adjust the patrol-region-interval to “10ms”, which will speed up patrolling regions, but will consume more CPU.

A large number of empty regions appear in the cluster, but they cannot be merged. There is also a special case: a large number of tables have been created and then emptied (Truncate operation is also considered to create a table). At this time, if the split table feature is enabled, these empty regions cannot be merged. At this time, you need to adjust the following parameters to turn off this feature :
- TiKV
  - Set split-region-on-table to false, this parameter does not support dynamic modify.
- PD
  - The key-type is set to txn or raw, and this parameter supports dynamic modify
  - Key-type maintains a table and sets enable-cross-table-merge to true. This parameter supports dynamic modify
- Normally, if the cluster is built in TiDB (pd+tiDB+TiKV), key-type is recommended to be set to table and used with the enable cross table parameter. If you are in rawKV mode (PD+TiKV only), you can choose the value of the key-type parameter depending on the rawapi and txnapi used.
- After turning on placement-rules, please switch txn and raw reasonably to avoid not being able to decode the key properly.

