简体   繁体   中英

ViewField order in SPQuery affecting performance

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.

My guess would be because of the nature of the SharePoint database (ie the AllItems table) which is actually doing multiple joins in order to 'build' the columns of a list.

So I guess it should really depend on the data distribution in your list (joining {small x small x big} or {big x small x small} tables)

For example in a LIST with following data distribution it would take more time for sharepoint to bring up the data in order BAC than ABC

LIST

   A   B   C
---------------
|    | K1 |    |
| N1 |----|    |
|    | K2 |    |
|----|----|    |
|    |    |    |
|    | K1 | Z1 |
| N2 |    |    |
|    |----|    |
|    | K2 |    |
|    |----|    |
|    | K3 |    |
|----|----|    |

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM