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

Community site session details

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

Use of indexes

(0) ShareShare
ReportReport
Posted on by 55

Hello,

I'm a bit confused about the usage of the index parameter in x++ select statements :

I always thought specifying an index will make the sql statement use that specific index. In the past I improved the performance of certain operations by adding indexes and 'using' them in the statement and witnessed dramatic performance gains. Not sure if this was because of adding the index on the table or specifying it in the statement. Recently, I'm seeing a lot of code that does not specify any indexes in the select/while select statements and I started wondering why so many people are not using indexes and thought this can't be just negligence.

The first thing I learned is that not INDEX but INDEX HINT actually enforces usage of a specific index. However, I also learned that HINT is also deprecated.

docs.microsoft.com/.../deprecated-x-index-hint-clause

According to Microsoft, the index only affects the order of the records returned :

https://docs.microsoft.com/en-us/dynamicsax-2012/developer/index-and-order-by-in-select-statements

If the conclusion is that a INDEX parameter on X++ sql statement does not help to decide on what index to use, how does X++ actually use the indexes for performance ? Does it pick them automatically based on what's the criteria in the where clause ?

Thanks

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    236,495 Most Valuable Professional on at
    RE: Use of indexes

    X++ doesn't decide which index should be used - this decision is done by the query optimizer of the database server. It evaluates the query, indexes, statistics...

    If you enforce a particular index, you prevent the optimizer from selecting an index that would be better in a particular case. Therefore enforcing indexes should be an exception, not a rule. You must be sure that you're making things better, not worse.

    In F&O, index hint clause is ignored unless it's explicitly enabled by allowIndexHint(true). Therefore if somebody uses index hint without thinking, or if you have legacy code with plenty of index hints, it's not a problem - they're ignored and the query optimizer can do its job.

  • Darrell Crews Profile Picture
    55 on at
    RE: Use of indexes

    Martin,

    thank you. So, basically in a statement like this...

    select * from SalesTable index salesIdIdx where SalesTable.SalesId == '123'

    ... the index salesIdIdx can or should be omitted since the query optimizer will likely pick that index. For optimal performance, one just needs to make sure good indexes are in place ?

    Best regards

  • André Arnaud de Calavon Profile Picture
    299,407 Super User 2025 Season 2 on at
    RE: Use of indexes

    Hi Darrell,

    You can read more about index hints in Dynamics 365 here: Enabling index hints in X++ again.

    Most likely, in your example, the SalesIdIdx will be used. When you notice a poor performance and you have the details that a wrong index is used in certain scenario's you can put an index hint to prevent the query optimizer from choosing the incorrect index. In the cases where it would be a viable option, mostly multiple fields are part of the index and select statements. 

  • Martin Dráb Profile Picture
    236,495 Most Valuable Professional on at
    RE: Use of indexes

    Your example isn't about index hint at all. It uses 'index' instead of 'index hint', which - as you correctly mentioned above - is used for sorting and not to enforce a particular index. I don't see it use at all - developers usually used 'order by' instead, as usual in SQL.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,933

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 537 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans