Query optimizer: fixed the cost overflow bug. Fixed non-determenisitc offsetkey test to handle inserts at the key position. Fixes #1616, fixes #1625.