Fix number of rows returned when limit is present or pagination is needed