Cursor open optimize

Several optimizations that are aimed at improving the performance of opening cursors when there are lots of tables.