sql optimisation of agreement list