# Merge
+ Two regions are merged into one region
+ Why merge
  + Data can be deleted
  + Too much regions implies cost (e.g. heartbeat, region cache, memory)
  + Transaction in the same region can be optimized by `1PC`
+ When to merge
  + If the size of region is too small
  + The key count of region is not many 
+ Two phase merge
  + **`Region 2`** merges into **`Region 1`**
  + Move replicas of both regions to the same nodes
  + **`Region 2`** starts merging, stops read/write operations
  + **`Region 1`** deletes metadata of **`Region 2`**, and extends its key range
  + **`Version = max(Region 1, Region 2) + 1`**

![`smart`](RaftRegionMerge_aa_001_20221023.png)

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

