0

I want to bulk load a few items from a list. The Caml is something like this:

<View><Query><Where>
   <Gt><FieldRef Name=\'ID\'/><Value Type=\'Number\'>{id}</Value></Gt>
</Where></Query><RowLimit>5000</RowLimit></View>

where {id} is the id from the last element of the previous query

This works fine on my testdata. But can I be sure that the ids from that query are always incremental? In other words: Is the default order always by id?

Or do I have to add an <OrderBy>-statement?

The reason for asking is that an orderby might affect the performance which I do not want.

3 Answers 3

1

If you don't specify an order, there is an implied order based on ID since in SharePoint IDs increase as rows are added and there is always an index on ID even if there are no other indexes on the list. However, implied is not guaranteed. The CAML specification doesn't list a default field for sorting if none is specified.

If the order is required by the use case, add ORDERBY. You would have to test to verify but I doubt there would be any performance hit since, as you see by your test data so far, the data is generally already sorted in ID order.

1

Yes as default a list is sorted by ID, so if that's what you don't have to include <OrderBy>

-1

In your query, you are using view tag. Are you querying based on a specific view? If not, then better remove it, otherwise make sure you specify which view. It is best that you use orderby as the query could change, probably the query is based on the default view. Try to change the orderby in the default view of your list/library and see what happens when you query the data.

Use Caml Query Builder for quick tests.

1
  • RowLimit requires a View
    – Ole Albers
    Sep 26, 2018 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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