optimize level migrate.total two sql query