Skip to content

Linq performance issue with non cacheable linq query plan  #2952

Closed
@gokhanabatay

Description

@gokhanabatay

Hi,
We have a performance issue with below linq query is not added to query plan cache. Because x.F2.Mask(6, 4, '*', MaskOption.Default) of this function call makes query uncacheable. This function is masks card number middle digits other than first 6 and last 4 digits. This api called concurrent 100 request at the same time.

First of all why this function call leads to query plan uncacheable, is this desired behaviour?
When we look at Dynatrace pure path below image added there is a suspension at QueryTranslatorImpl.Compile that I cannot understand and takes to much time to compile the query?

To report all uncacheable queries could you change QueryPlanCache.GetHqlQueryPlan log.Debug("Query plan not cacheable") to log.Warn("Query plan not cacheable {0}", queryExpression.Key) Adding elapsed time could be better for performance issues, we cannot find this issue without Dynatrace.

Environment
NHibernate 5.3.9
.net 5.0
linux container

            var transactions = Query<TxnAcquirerOnl>().WithOptions(opt => opt.SetReadOnly(true))
                                                   .Where(predicateTxnAcquirerOnl)
                                                   .OrderByDescending(order => order.Guid)
                                                   .Select(x => new GetTransactionsResponse
                                                   {
                                                       TxnGuid = x.Guid,
                                                       CardNo = x.F2.Mask(6, 4, '*', MaskOption.Default),
                                                       CardDci = x.CardDci,
                                                       CardSource = x.CardSource,
                                                       TerminalType = x.TerminalType,
                                                       TransactionName = x.TxnDef.Description.GetText(CurrentLanguage),
                                                       TxnEffect = x.TxnDef.TxnEffect,
                                                       TxnEntry = x.TxnEntry,
                                                       TransactionStatus = x.TxnStt,
                                                       TransactionDate = x.F13,
                                                       TransactionTime = x.F12,
                                                       TxnRegion = x.TxnRegion,
                                                       BinProductType = x.BinProductType,
                                                       MerchantCode = x.F42,
                                                       MerchantName = x.F43Name,
                                                       MerchantLocation = x.F43,
                                                       MerchantCity = x.F43City,
                                                       MerchantCountry = x.F43Country,
                                                       TerminalCode = x.F41,
                                                       TerminalStan = x.F11Trm,
                                                       BatchNo = x.BatchNo,
                                                       InstallCount = x.TxnAcquirerInstall.InstallCnt,
                                                       AuthCode = x.F38,
                                                       Rrn = x.F37,
                                                       ResponseCode = x.F39,
                                                       ResponseDescription = x.TxnResponseCodeDef.Description.GetText(CurrentLanguage),
                                                       Irc = x.Irc,
                                                       IrcDescription = x.TxnIrcDef.Description.GetText(CurrentLanguage),
                                                       Mcc = x.F18,
                                                       RequestDate = x.RequestDate,
                                                       RequestTime = x.RequestTime,
                                                       TransactionAmount = x.F4,
                                                       TransactionCurrency = x.F49,
                                                       BillingAmount = x.F6,
                                                       BillingCurrency = x.F51,
                                                   }).ToList()

SQL:

select
	txnacquire0_.guid as col_0_0_,
	txnacquire0_.f2 as col_1_0_,
	txnacquire0_.card_dci as col_2_0_,
	txnacquire0_.card_source as col_3_0_,
	txnacquire0_.terminal_type as col_4_0_,
	OCN_CFG.FN_GET_LANGUAGE_TEXT(txndef1_.description,
	:p0) as col_5_0_,
	txndef1_.txn_effect as col_6_0_,
	txnacquire0_.txn_entry as col_7_0_,
	txnacquire0_.txn_stt as col_8_0_,
	txnacquire0_.f13 as col_9_0_,
	txnacquire0_.f12 as col_10_0_,
	txnacquire0_.txn_region as col_11_0_,
	txnacquire0_.bin_product_type as col_12_0_,
	txnacquire0_.f42 as col_13_0_,
	txnacquire0_.f43_name as col_14_0_,
	txnacquire0_.f43 as col_15_0_,
	txnacquire0_.f43_city as col_16_0_,
	txnacquire0_.f43_country as col_17_0_,
	txnacquire0_.f41 as col_18_0_,
	txnacquire0_.f11_trm as col_19_0_,
	txnacquire0_.batch_no as col_20_0_,
	txnacquire2_.install_cnt as col_21_0_,
	txnacquire0_.f38 as col_22_0_,
	txnacquire0_.f37 as col_23_0_,
	txnacquire0_.f39 as col_24_0_,
	OCN_CFG.FN_GET_LANGUAGE_TEXT(txnrespons3_.description,
	:p1) as col_25_0_,
	txnacquire0_.irc as col_26_0_,
	OCN_CFG.FN_GET_LANGUAGE_TEXT(txnircdef4_.description,
	:p2) as col_27_0_,
	txnacquire0_.f18 as col_28_0_,
	txnacquire0_.request_date as col_29_0_,
	txnacquire0_.request_time as col_30_0_,
	txnacquire0_.f4 as col_31_0_,
	txnacquire0_.f49 as col_32_0_,
	txnacquire0_.f6 as col_33_0_,
	txnacquire0_.f51 as col_34_0_
from
	OCN_ACQ.TXN_ACQUIRER_ONL txnacquire0_
left outer join OCN_CFG.TXN_DEF txndef1_ on
	txnacquire0_.txn_def_guid = txndef1_.guid
left outer join OCN_ACQ.TXN_ACQUIRER_INSTALL txnacquire2_ on
	txnacquire0_.guid = txnacquire2_.txn_guid
left outer join OCN_CFG.TXN_RESPONSE_CODE_DEF txnrespons3_ on
	txnacquire0_.f39 = txnrespons3_.code
left outer join OCN_CFG.TXN_IRC_DEF txnircdef4_ on
	txnacquire0_.irc = txnircdef4_.code
where
	txnacquire0_.STATUS = :p3
	and txnacquire0_.MBR_ID = :p4
	and txnacquire0_.f42 =:p5
	and cast(cast(txnacquire0_.f13 as text)|| LPAD(cast(txnacquire0_.f12 as text), '*****', '*****') as numeric('*****'))<=:p6
	and cast(cast(txnacquire0_.f13 as text)|| LPAD(cast(txnacquire0_.f12 as text), '*****', '*****') as numeric('*****'))>=:p7
order by
	txnacquire0_.guid desc

Suspension: total 51.5 ms is too much
image

Another pure path without Suspension but 1.72 ms too much for this kind of query for every request
image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions