Fix limit processing for queries