我目前正在尝试调整一个有问题的存储过程,并且我已经注意到,与运行该存储过程相关的大部分成本来自将某些XML解析为临时表的解析。这是有问题的SQL:
CREATE TABLE #ChangeSet
(
RemarkTypeID TINYINT NOT NULL PRIMARY KEY,
RemarkText VARCHAR(2500) NOT NULL,
ListingID INT NOT NULL
)
INSERT INTO #ChangeSet
(RemarkTypeID,
RemarkText,
ListingID)
SELECT
T.c.value('@RemarkTypeID[1]','tinyint') AS RemarkTypeID,
T.c.value('@RemarkText[1]','varchar(2500)') AS RemarkText,
@ListingID
FROM @RemarksXml.nodes('/Remarks[1]/Remark') AS T(c)
此外,因此您对要解析的XML的结构有一些了解:
<Remarks>
<Remark xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" RemarkID="211767" DateTimeCreated="1991-11-19T10:43:50" DateTimeModified="1992-01-01T10:43:50" RemarkTypeID="8" RemarkText="aaaWasher,Dryer,Refriger,Microwav" />
<Remark xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" RemarkID="211768" DateTimeCreated="1991-11-19T10:43:50" DateTimeModified="1992-01-01T10:43:50" RemarkTypeID="3" RemarkText="aaaell Maintained 3Bd 1.5Ba Semi-Detached Home In Cambridge Gardens. Garage W As Converted Into A Nice Family Room The Outside Is Maintence Free. Includes All Appliances,Security System,Storage Shed,Ceiling Fans And New Carpet.This Home Is Very Well Pricded. Seller Will Consider Fha Or Va Along With Conventional Finacing. This Is A Great Buy." />
</Remarks>
我可以做些什么来提高解析这些XML节点和设置此临时表的性能?
xml是否作为参数传递?
—
World Wide DBA
您的XML有多大,有多少个“请求”节点,速度有多慢?XML查询的成本是没有用的,并且不会告诉您实际的性能。
—
Mikael Eriksson