如何使XML解析存储过程运行得更快

时间:2015-08-05 16:27:26

标签: sql sql-server

我有一个显示在这里的存储过程;它在XML列中搜索类型为(TEXT)并查找要匹配的输入参数(名字和姓氏或电话或号码)。问题是存储过程运行得非常慢,无法通过所有记录。反正有没有让它更快? (我使用了强制转换因为列是TEXT类型将其转换为XML并替换,因为某些XMLS有额外的)

CREATE PROCEDURE [dbo].[Tracker]
     @FirstName varchar(100) 
    ,@LastName  varchar(100)  
    ,@Phone     varchar(100)  
    ,@Number    varchar(100)  
 AS
 BEGIN
     SET NOCOUNT ON;

     SELECT 
         [Id], [Type], [Response], [Modified], [Created],
         [bSalesforce], [Request], [Application_Filename], [AffiliateId] 
     FROM
         [Tracker]  
     WHERE
         CAST(REPLACE(CAST(Request AS varchar(max)), '\"', '"') AS xml).value('(/I/Credit/LoanApp/LoanRq/Applicant/Personal/Individu 
 als/Individual/GivenName/FirstName/text())[1]', 'NVARCHAR(max)') = @FirstName    
         AND CAST(REPLACE(CAST(Request AS varchar(max)), '\"', '"') AS 
       xml).value('(/I/Credit/LoanApp/LoanRq/Applicant/Personal/Individu
 als/Individual/GivenName/LastName/text())[1]', 'NVARCHAR(max)') = @LastName 
         OR CAST(REPLACE(CAST(Request AS varchar(max)), '\"', '"') AS 
     xml).value('(/I/Credit/LoanApp/LoanRq/Applicant/Personal/Individu
 als/Individual/phone/text())[1]', 'NVARCHAR(max)') = @phone 
         OR CAST(REPLACE(CAST(Request AS varchar(max)), '\"', '"') AS xml).value('(/I/Credit/LoanApp/LoanRq/Applicant/Routing/From/Number/text())[1]', 'NVARCHAR(max)') = @Number
END

0 个答案:

没有答案