Backport new doModifyLimitQuery method from 2.4.