reduce sql query in permission