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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)
New Discussion

X++ Group by is generating an SQL Group By with an extra Order by

(0) ShareShare
ReportReport
Posted on by 425

Hello AX community, 

I would like your inputs on a recent performance topic we had internally.

When we execute a select statement in X++ including a Group By, AX will generate a SQL query including an extra Order By on every field that we put in the x++ Group by.

For example, the following X++ statement:

DimensionFocusBalanceCalculationView balanceView;
    
select generateonly AccountingDate, Ledger, PostingLayer, FiscalPeriodType,
        FocusLedgerDimension, FocusDimensionHierarchy,
        sum(AccountingCurrencyAmount), sum(ReportingCurrencyAmount),
        sum(Quantity) from balanceView
    group by FocusLedgerDimension, FocusDimensionHierarchy,
        AccountingDate, Ledger, PostingLayer, FiscalPeriodType, IsCredit;
    
info(balanceView.getSQLStatement());


The info output will show the SQL Query (thanks to the generateOnly):

SELECT SUM(T1.ACCOUNTINGCURRENCYAMOUNT),SUM(T1.REPORTINGCURRENCYAMOUNT),SUM(T1.QUANTITY),T1.FOCUSLEDGERDIMENSION,T1.FOCUSDIMENSIONHIERARCHY,T1.ACCOUNTINGDATE,T1.LEDGER,T1.POSTINGLAYER,T1.FISCALPERIODTYPE,T1.ISCREDIT 
	FROM DIMENSIONFOCUSBALANCECALCULATIONVIEW T1 
WHERE ((((PARTITION=5637144576) AND (PARTITION#2=5637144576)) AND (PARTITION#3=5637144576)) AND (PARTITION#4=5637144576))
	GROUP BY T1.FOCUSLEDGERDIMENSION,T1.FOCUSDIMENSIONHIERARCHY,T1.ACCOUNTINGDATE,T1.LEDGER,T1.POSTINGLAYER,T1.FISCALPERIODTYPE,T1.ISCREDIT 
	ORDER BY T1.FOCUSLEDGERDIMENSION,T1.FOCUSDIMENSIONHIERARCHY,T1.ACCOUNTINGDATE,T1.LEDGER,T1.POSTINGLAYER,T1.FISCALPERIODTYPE,T1.ISCREDIT

If we look to the SQL execution Plan, we can see that the "Sort" operation is costing more than 80% of the total cost of the query...


25_2D00_05_2D00_2018-11_2D00_27_2D00_06.png

Questions: 

  • We found a workaround, by forcing an order RecId in X++, that will bypass the extra Order By, but we can't customize every query of AX... so we are looking for a global solution!
  • Is there any Server Parameter that can disable the extra Order By clause in the generated query ?

Reproducible on:

  • MS Dynamics AX R2 CU9
  • MS Dynamics AX R3 CU13

Regards

FX

*This post is locked for comments

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Sanhthosh.Kumar.K Profile Picture

Sanhthosh.Kumar.K 2

#2
Raed Salah Bzour Profile Picture

Raed Salah Bzour 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans