fix scan merge and speed up merge optimizer