Fix overlapping query bug.