Duplicate queries in logs

There are duplicate queries in the logs. This was caused by the constraint set not being ordered, generating a slightly different query each time. Since the queries were not exactly the same so the cache couldn't be used.