Currently, the msck repair table command batches the number of partitions created in the metastore using the config HIVE_MSCK_REPAIR_BATCH_SIZE. Following snippet shows the batching logic. There can be couple of improvements to this batching logic:
1. If the batch size is too aggressive the code falls back to adding partitions one by one which is almost always very slow. It is easily possible that users increase the batch size to higher value to make the command run faster but end up with a worse performance because code falls back to adding one by one. Users are then expected to determine the tuned value of batch size which works well for their environment. I think the code could handle this situation better by exponentially decaying the batch size instead of falling back to one by one.
2. The other issue with this implementation is if lets say first batch succeeds and the second one fails, the code tries to add all the partitions one by one irrespective of whether some of the were successfully added or not. If we need to fall back to one by one we should atleast remove the ones which we know for sure are already added successfully.