Improve statev_sql performance for sqlite.

Set magic parameters according to
http://stackoverflow.com/questions/1711631/how-do-i-improve-the-performance-of-sqlite.
Emit statistic events for Perm restore moves.
Emit more finely-grained statistic events for Perm nodes.
statev_sql: Remove unused variables.
statev_sql: Cache and reuse context ids.