I find that session's DBStore can be made to have less "SELECT * FROM sessions" queries.
For example, it selects the session to decide if it exists in __setitem__ when performing if key in self: check.
if key in self:
But as I understand db.update already returns the number of updated records, and we could use it to check if db.insert is needed.
if self.db.update(self.table, where="session_id=$key", data=pickled, vars=locals()) != 1:
self.db.insert(self.table, False, session_id=key, data=pickled)