Quantcast
Channel: Microsoft Dynamics AX Forum - Recent Threads
Viewing all articles
Browse latest Browse all 175888

Bad query plan from Ax but not in SQL

$
0
0

Good Afternoon,

We are working on some performance problem in AX. Basically the issue we have is that the query executed from AX (Trial balance>Posted) takes 2 minutes whereas same query runs in SQL in 1 second. The query is:

SELECT T1.TRANSACTIONCURRENCYAMOUNT,T1.ACCOUNTINGCURRENCYAMOUNT,T1.REPORTINGCURRENCYAMOUNT,T1.QUANTITY,T1.ALLOCATIONLEVEL,T1.ISCORRECTION,T1.ISCREDIT,T1.TRANSACTIONCURRENCYCODE,T1.PAYMENTREFERENCE,T1.POSTINGTYPE,T1.LEDGERDIMENSION,T1.GENERALJOURNALENTRY,T1.TEXT,T1.REASONREF,T1.PROJID_SA,T1.PROJTABLEDATAAREAID,T1.HISTORICALEXCHANGERATEDATE,T1.LEDGERACCOUNT,T1.MAINACCOUNT,T1.CREATEDTRANSACTIONID,T1.RECVERSION,T1.PARTITION,T1.RECID,T2.ACCOUNTINGDATE,T2.ACKNOWLEDGEMENTDATE,T2.POSTINGLAYER,T2.JOURNALNUMBER,T2.SUBLEDGERVOUCHER,T2.DOCUMENTDATE,T2.DOCUMENTNUMBER,T2.JOURNALCATEGORY,T2.LEDGERENTRYJOURNAL,T2.RECVERSION,T2.RECID,T3.DISPLAYVALUE,T3.RECVERSION,T3.RECID,T4.TYPE,T4.RECVERSION,T4.RECID
FROM GENERALJOURNALACCOUNTENTRY T1
CROSS JOIN GENERALJOURNALENTRY T2
LEFT OUTER JOIN DIMENSIONATTRIBUTEVALUECOMBINATION T3
ON ((T3.PARTITION=5637144576) AND ((T3.LEDGERDIMENSIONTYPE=0) AND (T1.LEDGERDIMENSION=T3.RECID)))
CROSS JOIN FISCALCALENDARPERIOD T4 WHERE ((T1.PARTITION=5637144576) AND (T1.MAINACCOUNT=5637145446)) AND ((T2.PARTITION=5637144576)
AND ((T2.LEDGER=5637144848) AND (T1.GENERALJOURNALENTRY=T2.RECID))) AND ((T4.PARTITION=5637144576) AND (T2.FISCALCALENDARPERIOD=T4.RECID)) AND
EXISTS (SELECT ''x'' FROM DIMENSIONATTRIBUTEVALUEGROUPCOMBINATION T5
CROSS JOIN DIMENSIONATTRIBUTELEVELVALUE T6
WHERE ((T5.PARTITION=5637144576) AND (T3.RECID=T5.DIMENSIONATTRIBUTEVALUECOMBINATION)) AND ((T6.PARTITION=5637144576) AND ((T6.DIMENSIONATTRIBUTEVALUE=5637276267) AND (T5.DIMENSIONATTRIBUTEVALUEGROUP=T6.DIMENSIONATTRIBUTEVALUEGROUP))))
ORDER BY T2.ACCOUNTINGDATE DESC,T2.JOURNALNUMBER DESC,T2.SUBLEDGERVOUCHER DESC OPTION(FAST 20)

We have forceliterals hint turned on for that form, so all the values are submitted directly.

I made some investigation and seems that query plan is different for the query directly executed in SSMS (good performance) and executed from AX (bad performance). I caught the full statement from AX with SQL profiler and it is executed as cursor:

declare @p1 int
set @p1=0
declare @p3 int
set @p3=24592
declare @p4 int
set @p4=8193
declare @p5 int
set @p5=26
exec sp_cursoropen @p1 output,
N'<query, identical as above>',@p3 output,@p4 output,@p5 output
select @p1, @p3, @p4, @p5

To be sure that query plan is properly chosen we updated the statistics and cleared proc cache. But no luck: still query plans are different and the one for AX is less optimal.

Do you have any ideas how to proceed with that?

1. Is it possible to force SQL server to use better query plan?
2. Is it possible to control AX behaviour: creating of query using cursor (eg. using different parameters). I think this is controlled by the kernel, but maybe there is a way for doing that.

BR,

Maciej

Ax version: Dynamics AX 2012 r3 CU9


Viewing all articles
Browse latest Browse all 175888

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>