我有一个存储过程,它接受XML参数。然后我从这个参数中选择并插入临时表。
如果XML参数的长度很小,那么一切都很好。但是,当传入大的XML值时,性能会下降。
只需从XML参数中选择就可以了,问题是当我尝试从select中插入时。
DECLARE @OptionalTagXml XML
SET @OptionalTagXml = 'some very long XML string'
CREATE TABLE #OptionalTags (
[value] varchar(100),
[description] varchar(100)
)
-- Introducing this line causes very slow performance, the select by itself is fine.
--INSERT INTO #OptionalTags ([value], [description])
SELECT TagValue.value('(./value)[1]', 'varchar(100)') AS [value],
TagValue.value('(./description)[1]', 'varchar(100)') AS [description]
FROM @OptionalTagXml.nodes('/tags/tag') AS T(TagValue)
DROP TABLE #OptionalTags
这里有一个示例XML结构:
SET @OptionalTagXml = '<tags><tag><description>ViewPermissionCustomerId</description><value>1028996</value><group>0</group></tag><tag><description>ViewPermissionBrandId</description><value>2</value><group>0</group></tag><tag><description>ViewPermissionBrandId</description><value>1</value><group>0</group></tag><tag><description>ViewPermissionCustomerId</description><value>1028997</value><group>0</group></tag><tag><description>ViewPermissionCustomerId</description><value>1033094</value><group>0</group></tag><tag><description>ViewPermssionCustomerId</description><value>1028999</value><group>0</group></tag><tag><description>ViewPermissionCustomerId</description><value>1028998</value><group>0</group></tag><tag><description>ViewPermissionCustomerId</description><value>1029000</value><group>0</group></tag><tag><description>ViewPermissionCustomerId</description><value>1029001</value><group>0</group></tag><tag><description>ViewPermissionCustomerId</description><value>1033368</value><group>0</group></tag><tag><description>ViewPermissionCustomerId</description><value>1028882</value><group>0</group></tag><tag><description>ViewPermissionCustomerId</description><value>1033369</value><group>0</group></tag><tag><description>ViewPermissionCustomerId</description><value>1029002</value><group>0</group></tag><tag><description>ViewPermissionCustomerId</description><value>1030235</value><group>0</group></tag><tag><description>ViewPermissionCustomerId</description><value>1029003</value><group>0</group></tag><tag><description>ViewPermissionCustomerId</description><value>1033370</value><group>0</group></tag><tag><description>ViewPermissionCustomerId</description><value>1029005</value><group>0</group></tag><tag><description>ViewPermissionCustomerId</description><value>1033371</value><group>0</group></tag><tag><description>ViewPermissionCustomerId</description><value>1028995</value><group>0</group></tag><tag><description>ViewPermissionCustomerId</description><value>1034356</value><group>0</group></tag></tags>'
不幸的是我无法添加一个有问题的例子,因为它的长度超过了帖子的字符限制,但从透视的角度来看,上面的例子是1994个字符,而有问题的例子可能是50,000字符的区域。
理解这个问题或任何其他方法的任何帮助都将受到赞赏。