I've encountered a strange issue when writing an SPQuery and specifying ViewFields. I have eight fields that I need. Five of them are indexed.
My issue is that depending on the order in which I specify these ViewFields the performance of my query is drastically changed.
Here are two scenarios:
1:
<FieldRef Name="OrderNumber" />
<FieldRef Name="Title" />
<FieldRef Name="OrderCreateDate" />
<FieldRef Name="OrderEstimatedDeliveryDate" />
<FieldRef Name="OrderStatus" />
<FieldRef Name="OrderOO" />
<FieldRef Name="OrderSiteID" />
<FieldRef Name="ID" />
2:
<FieldRef Name="OrderNumber" />
<FieldRef Name="Title" />
<FieldRef Name="OrderCreateDate" />
<FieldRef Name="OrderEstimatedDeliveryDate" />
<FieldRef Name="OrderSiteID" />
<FieldRef Name="OrderStatus" />
<FieldRef Name="OrderOO" />
<FieldRef Name="ID" />
The fields that are indexed are:
OrderNumber
Title
OrderCreateDate
OrderSiteID
OrderStatus
When running the query with the ViewFields in the first order it takes 4.7 seconds. Running the query in the second order takes 62 seconds. Nothing else with the query is changed when I tested.
The query is returning a large amount of data, so I don't expect it to be blazing fast, but can anyone help as to why changing the order of the ViewFields has such a large impact?
Thanks.