简体   繁体   English

串联时性能低下

[英]Low performance on concatenation

I am using the following code to select my desired rows but the problem is it has low performance on select DocumentNumber column from other table that the problem is on this part ---> ('IN-'+@ItemStatus+'#'+chequeserial) 我正在使用以下代码来选择所需的行,但问题是该表上的问题来自其他表的Select DocumentNumber列上的性能很差--->('IN-'+ @ ItemStatus +'#'+ chequeserial )

SELECT     
    Banking.ReceivedCheque.Date, Banking.ReceivedCheque.StatusDate,
    Banking.ReceivedCheque.DueDate, Banking.ReceivedCheque.ChequeSerial, 
    Banking.ReceivedCheque.BankName Banking.ReceivedCheque.CompanyInfoFK, 
    Banking.ReceivedCheque.FinancialPeriodFK, 
    Banking.ReceivedCheque.CreditGFK, Banking.ReceivedCheque.CreditID, 
    ReceivedFromAccount = dbo.getname(CreditID, CreditGFK, FinancialPeriodFK),
    DefBankAccount = dbo.getname(DefaultBankID, '4', FinancialPeriodFK), 
    Banking.ReceivedCheque.StatusFK,
    Banking.ChequeStatus.Title,
    (SELECT MAX(DocumentFK) 
     FROM Accounting.DocumentDetail 
     WHERE ItemFK = ('IN-' + @ItemStatus + '#' + chequeserial)  
       AND financialPeriodFK = @FinancialPeriodFK) AS DocumentNumber
FROM         
    Banking.ReceivedCheque 
INNER JOIN
    Banking.ChequeStatus ON Banking.ReceivedCheque.StatusFK = Banking.ChequeStatus.ChequeStatusID
WHERE
    ReceivedCheque.FinancialPeriodFK = @FinancialPeriodFK  
    AND Banking.ReceivedCheque.StatusFK = @StatusFK

Please let me know if there is any other solution to increase performance. 请让我知道是否还有其他解决方案可以提高性能。

It looks like @ItemStatus is a scalar parameter. 看起来@ItemStatus是一个标量参数。 Can you do this portion of the operation once rather than for every row of the comparison? 您可以一次执行该部分操作,而不是对比较的每一行进行一次吗? You'd eliminate many behind the scene concatenations. 您将消除许多幕后串联。

set @InItemStatusPound = 'IN-'+@ItemStatus + '#'

ItemFK=(@InItemStatusPound+chequeserial)

This is typically one of the reason's lookup tables have foreign keys based on numeric values like int rather than string values. 通常,原因之一是查找表具有基于数字值(例如int)而不是字符串值的外键。 Is performing your join on an integer rather than a string that requires concatenation an option? 是在整数而不是需要连接的字符串上执行连接吗?

Note: If you could guarantee that the string would be less than 32 bits, using strings rather than int values is just fine. 注意:如果可以保证字符串小于32位,则使用字符串而不是int值就可以了。 They're advantage is their compactness. 他们的优势是紧凑。

Sage Advice: Typically, if something hurts, figure out how not to do it. 贤哲忠告:通常,如果有什么东西疼,请找出不这样做的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM