Fix bug in scan merge optimization reported by Yao Li.