Using cursors and indexes