SharePoint Troubleshooting: 5000 list view threshold limit issue

Many times when we deal with big lists in SharePoint, we get the error : "This view cannot be displayed because it exceeds the list view threshold (5000 items) enforced by the administrator". In this article we will learn about the root cause of this error and a work around to fix this. 

Introduction

The threshold concept was introduced in SharePoint 2010 considering the performance issue while loading a big list to improve the query performance. There is an incorrect perception about the SharePoint list view threshold 5000 error - many users think that the SharePoint list/library just can store 5000 items but that is not true, in fact, SharePoint list can store 30 million items. Then why are we getting this error? Before we analyze about this error I recommend you to read my previous articles "SharePoint : Concept of indexing column" and "SharePoint: Steps to create indexing column and its importance"

Why do we get a 5000 threshold error?

This error actually comes from SQL, not from SharePoint. As I have explained in my previous article "Overview Of SharePoint Column Indexing" there we have seen that the SharePoint stores all of its list data and list columns in single SQL table, i.e. "AllUserData" table.

 

Now we need to learn how the query gets processed. 

When we browse a list or library SharePoint sends a query to SQL and SQL process that query and send the result to SharePoint, then finally we can see the result i.e. nothing but list or library items in the browser. Let's take an example of "All Items" view (assuming that no filters were applied on it) - when we click on this view SharePoint will build a query and pass this on to SQL, then SQL processes that query and sends the result to SharePoint. Now if the results returned by the query are more than 5000 then the user gets the below-mentioned list view threshold error.

↑ Return to Top

Why does this limitation set as 5,000 in SQL?

Due to the performance reasons, if SQL server performs the query on a single table (here it is: “AllUserData” table) which would result in the output being more than 5000 items, in this case, the SQL server will lock the entire table while the query execution is on – this is the default behavior of SQL by the designed.

 

So when the "AllUserData" table is locked – what will happen?

 

So far as we have learned that SharePoint stores all list/library data in a single table i.e “AllUserData” – a single query which returns more than 5,000 items will lock all of the list and library data for that entire content database.

 

In this scenario – the business users who were accessing content in SharePoint from the same content site collection (content database) while the “AllUserData” table is locked, will have to wait a longer time for their results to be displayed.

 

By now we have learned about the root cause of threshold error and we need to focus on how to move on with this situation as the business has to run.

How to overcome the 5000 items list view threshold issue?

We can increase the list items limit from 5000 to 50000 (fifty thousand) in SharePoint on-premise, in fact, we can disable the list view threshold limit which is not all recommended but in SharePoint online we don’t have control over it, so we need to move on with the whatever limitation is set i.e. 5000.

 

Here based on my experience, I will list out some tips and tricks to avoid this issue which will work both for SharePoint online and on-premise.

  • Planning – before creating the list or library, analyze the data and plan accordingly. Try to split the data in multiple list or library.
  • Create multiple views and add “AND” condition in the list filter criteria, never add “OR” condition, “OR” condition will try to get all data.
  • Create index column – we can only have 20 indexed columns in a given list, so we need to plan this thoughtfully!
  • We cannot create an indexed column if the list is already hitting the list view threshold limit.
  • Maintain the archive list – here we need to review the list items periodically and need to check whether some items can be deleted or archived to another list – here we can write some automation job which will be moving the items periodically to another archive list automatically.
  • In the list filter criteria, we need to filter the list items such a way that at any given point of time list view will return less than 5000 items using filter on created column column technique(please see the explanation in the below).

Create filter using [Today]- "<number of days>" technique

Here one of the techniques is – create a filter on "Created" column and use the [Today]- “number of days” with less than or equal to condition, something like below:

Note:

The logic behind the filter on the created column is – this will try to get the items that will return less than 5000 items. If this condition also returns more than 5000 items, we need to split this up created column condition with multiple “AND” condition with the combination of some other column to ensure the filter returns less than 5000 items as a below example – though the implementation of this technique is time consuming.

↑ Return to Top

Practically – let us see what happens when a list exceeds the 5000 items

To check this we need to have a list which should have more than 5000 items. So I have created a list named "Test List" were adding more than 5000 items using the below PowerShell script to see what happens when it crosses the 5000 limit.

 001.CLS 
002.#Load SharePoint CSOM Assemblies  
003.#Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" 
004.#Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" 
005.     
006.$fileName = "Adding_Multiple_Items_Report" 
007.$enddate = (Get-Date).tostring("yyyyMMddhhmmss")  
008.$logFileName = $fileName +"_"+ $enddate+"_Log.txt"    
009.$invocation = (Get-Variable MyInvocation).Value    
010.$directoryPath = Split-Path $invocation.MyCommand.Path   
011.   
012.$directoryPathForLog=$directoryPath+"\"+"LogFiles"  
013.if(!(Test-Path -path $directoryPathForLog))    
014.        {    
015.            New-Item -ItemType directory -Path $directoryPathForLog  
016.               
017.        }     
018.           
019.$logPath = $directoryPathForLog + "\" + $logFileName    
020.$isLogFileCreated = $False   
021.   
022.#DLL location  
023.$directoryPathForDLL=$directoryPath+"\"+"Dependency Files"  
024.if(!(Test-Path -path $directoryPathForDLL))    
025.        {    
026.            New-Item -ItemType directory -Path $directoryPathForDLL  
027.                  
028.        }   
029.   
030.#DLL location  
031.$clientDLL=$directoryPathForDLL+"\"+"Microsoft.SharePoint.Client.dll"  
032.$clientDLLRuntime=$directoryPathForDLL+"\"+"Microsoft.SharePoint.Client.dll"  
033.   
034.Add-Type -Path $clientDLL  
035.Add-Type -Path $clientDLLRuntime  
036.     
037.   
038.function Write-Log([string]$logMsg)    
039.{     
040.    if(!$isLogFileCreated){     
041.        Write-Host "Creating Log File..."     
042.        if(!(Test-Path -path $directoryPath))    
043.        {    
044.            Write-Host "Please Provide Proper Log Path" -ForegroundColor Red     
045.        }     
046.        else     
047.        {     
048.            $script:isLogFileCreated = $True     
049.            Write-Host "Log File ($logFileName) Created..."     
050.            [string]$logMessage = [System.String]::Format("[$(Get-Date)] - {0}", $logMsg)     
051.            Add-Content -Path $logPath -Value $logMessage     
052.        }     
053.    }     
054.    else     
055.    {     
056.        [string]$logMessage = [System.String]::Format("[$(Get-Date)] - {0}", $logMsg)     
057.        Add-Content -Path $logPath -Value $logMessage     
058.    }     
059.}   
060.   
061.   
062.#variables region.  
063.$siteURL="https://globalsharepoint.sharepoint.com/sites/TestSite/"  
064.$spUserName="Global-sharepoint@globalsharepoint.onmicrosoft.com"  
065.$password = "ThisIsTestPassWord"  
066.$spListName="Test List"  
067.#$numberOfItemsToCreate="5001"  
068.#variables region end.  
069.   
070.$securePassword= $Password | ConvertTo-SecureString -AsPlainText -Force  
071.     
072.#Setup the Context  
073.   
074.try  
075.{  
076.$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)  
077.$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($spUserName, $securePassword)  
078.     
079.   
080.#Get the list  
081.$spList = $ctx.Web.Lists.GetByTitle($spListName)  
082.$ctx.Load($spList)  
083.$ctx.ExecuteQuery()  
084.   
085.#Loop thru to create the list items.  
086.for($i=1; $i -le 5001; $i++)  
087.{  
088.  $listItemCreationInformationInSPOnline = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation  
089.  $newListItemInSPOnline = $spList.AddItem($listItemCreationInformationInSPOnline)  
090.  $newListItemInSPOnline["Title"] = "CustomItemNumberAddedThruCode_1_$($i)"  
091.  $newListItemInSPOnline["CustomItemNumber"] = $i;  
092.  $newListItemInSPOnline.Update()  
093.  $ctx.ExecuteQuery()  
094.   
095.  write-host "Item created in SP Online list: $spListName  CustomItemNumberAddedThruCode_$($i)"  
096.}      
097.}  
098.catch   
099.{  
100.     
101.    $errorMessage = $_.Exception.Message +"in adding mulitple items  in SP Online list using CSOM PowerShell script";  
102.    Write-Host $errorMessage -BackgroundColor Red  
103.    Write-Log $errorMessage   
104.}  
105.            
106.Write-Host "####################################################################"  -ForegroundColor Green   
107.Write-Host "The script execution has been completed!" -ForegroundColor Green    
108.Write-Host "###################################################################"

Execute the above script like below:

Now if we go the list setting page (example as “Test List”), we can see the message like below which says this list exceeds the 5000 threshold limit.

↑ Return to Top

Is the 5000 limitation for all users?

No, 5000 limation is for the normal users and for the administrator limitation is higher; i.e., 20000.

 

What does it mean? 

 

When a normal user accesses a SharePoint list which has more than 5000 items, that user will get a 5000 listview threshold error mentioned above and list will not be opened with the data but the same list will be loaded with the data if it accessed by an administrator as it has higher limit i.e. 20000.  

Summary: What we had here?

 

Thus, in this article we have learned the below concept with respect to SharePoint list view threshold:

  • What is the threshold issue in SharePoint list.
  • Why do we get a 5000 threshold error?
  • Why does this limitation set as 5,000 in SQL?
  • How to overcome the 5000 items list view threshold issue?
  • Practically – saw what happens when a list exceeds the 5000 items.
  • What is the limitation for normal user and administrator? 

Note:

Having described the threshold limit issue and their possible workarounds to fix this in SharePoint – it's an impending open issue over a decade from Microsoft, which really Microsoft needs to fix or come up with some inbuilt alternate technique. This issue is one of the drawbacks of SharePoint which leads to many business user's dissatisfaction towards SharePoint. So Microsoft really needs to fix this issue in the long run!!!

References

See Also

↑ Return to Top