Resolving unexpected slow database queries after MySQL 5.7 upgrade