Close cursor when aggregating rows.