Optimize session.write from three to one sql-statement