missing-identity performance improvement.

Handling missing-identity messages was using an expensive sql query.
This has been replaced with two simple queries resulting in a
considerable performance improvement (all exising indexes can now be
properly used by sqlite).