Avoid perf issues in Mysql with large offsets in queries

Improves 2d9538eb771b4c622de2c2b42df5320b39e4123c