web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Link between primary index and cluster index in a table for performance improvement

(1) ShareShare
ReportReport
Posted on by 141
,Hi experts, 
I am trying to understand how indexing would increase performance in tables and should primary index and cluster index should be the same in order to get the performance improvement? 
The reason that I am asking whether it is linked is, I read somewhere stating that /Indexing will increase the speed of fetching the record from a table by using binary search/. My question here is, if primary key is given as xxxId should cluster index should be xxxId as well? Since binary search works only when the records are arranged in ascending order. If we don't arrange the records in a table in the order of primary index, will there not be any performance improvement unless we use the cluster index as index to search in select statements? I don't even know my understanding of increasing performance through binary search is right. Any inputs is appreciated. 
 
Thanks in advance, 
John
I have the same question (0)
  • Suggested answer
    Waed Ayyad Profile Picture
    9,039 Super User 2025 Season 2 on at
    Hi,
     
    Primary indexes are unique indexes and clustered may or may not be, it isn't necessary to have cluster index the same as the primary index and the cluster index depends on the physical order of the records on DB.
     
    You can check the below link about indexes:
     
    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue.
     
  • Suggested answer
    Anthony Blake Profile Picture
    2,926 Super User 2025 Season 2 on at
    At a high level, the clustered index is the physical order of the data - hence why you can only ever have one. Primary and clustered index being the same, such as in your example by ID, while there are of course other factors, should increase performance when querying data by ID. The primary index is used for looking up data, and if that index is looking directly at the table rather than referencing a separate index with pointers to table locations, there should be an improvement. The results will depend on other factors though, so I would copy data to an environment where I could do some benchmarking to discover the impact. You can take a look at the SQL execution plans in SSMS and see the difference.
  • John Bright Profile Picture
    141 on at
    Hi Anthony, 
     
    Thanks for your response.
    I did a bit of analysis in SSMS from my side. Here is what I found. 
    Basically, I took two tables one is the standard "PurchTable" and other is a custom table that I developed "xxxTable". I have given primary index and cluster index in my custom table the same xxxId as it was purchId in terms of PurchTable. I did some select statements and took a look at the execution plan. The thing that I found is, it says ordered as false in my custom table but it is true in the PurchTable. But if I just select all data in my custom table, it is actually ordered but the execution plan says it is not. I don't understand why! 
     
    Apart from this analysis what I am trying to understand is. Indexing improves performance because it performs binary search on querying data? What happens behind the scenes in sql. 
  • Suggested answer
    Raj Borad Profile Picture
    1,424 on at
    Hi John,
     
    The primary index of the table is by default RecId of the Table. You can also change it.
    As per my knowledge, At the time of extracting the data, Primary index column sorts first then Cluster index column.
    As you see in above SS of ProjItemTransCost Table.
    InventTransId which is (Primary Index) is different/unique for all the Records in the table but the ProjId is/may be the same.
     
    Thank you, 
    Raj D Borad

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans