Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I frequently read one should use RowLimit on SPQuerys on a large list, especially with more than 2000 items.

Best Practices: Common Coding Issues When Using the SharePoint Object Model:

An SPQuery object without a value for RowLimit will perform poorly and fail on large lists. Specify a RowLimit between 1 and 2000 and, if necessary, page through the list.

That doesn't make sense to me, as I think it should be "if you have a query with a huge result".

Can someone explain to me why one should use RowLimit even if the query returns no more than about 10 items? (eg on a list with thousand tasks and filtering for open tasks of the current user) Or are all the Best Practices telling wrong informations due to imprecise phrases?

share|improve this question
add comment

2 Answers 2

Use SPList.GetItems(SPQuery query) instead. Apply filters, if appropriate, and specify only the fields you need to make the query more efficient. If the list contains more than 2,000 items, you will need to paginate the list in increments of no more than 2,000 items. The following code example shows how to paginate a large list.

This implies that you need to paginate if you have a large list. It says this in the link provided. This rowlimit is only for pagination, and doesn't make sense for smaller lists.

share|improve this answer
1  
I have always thought it is really just a backup assurance that you will not query too many records. Like all best practices, you can chose to ignore them. Sometimes everything will be fine, and sometimes chaos will ensue. –  Mike Oryszak Aug 9 '12 at 21:26
    
Again my question: RowLimit is just for the size of the results by a query and the size of the list doesn't matter, am I right? So why is everyone talking about the size of a list? –  Athalis Aug 9 '12 at 22:56
    
Yes, it's to pull back that amount in, of your rowlimit, without touching all of the items in the list. –  Mike Aug 10 '12 at 13:38
add comment

Even if you write a query which will fetch 10 items from a list with large number of items, the Query will have to move through all those items and then determine which items pass your filtering criteria.

So fetching 10 items from a list with total 100 items will always be faster than fetching 10 items from a list with total 1000 items.

In your case, the query will have to move through all the tasks to determine which are open and which are closed right?

share|improve this answer
    
Yes, you are right, but therefore we index the column status to improve the fetch –  Athalis Aug 9 '12 at 22:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.