Fixing queries to add session_id support see BT#7852