简体   繁体   English

SQL 查询 XML 在 2000 年运行良好,在 2008 年 R2 运行缓慢

[英]SQL Query FOR XML runs fine in 2000, slow in 2008 R2

I'm converting a client's SSIS packages from DTS to SSIS.我正在将客户的 SSIS 包从 DTS 转换为 SSIS。 In one of their packages they have an execute SQL task that has a query similar to this:在他们的一个包中,他们有一个执行 SQL 任务,其查询类似于:

SELECT * FROM [SOME_TABLE] AS ReturnValues 
ORDER BY IDNumber
FOR XML AUTO, ELEMENTS

This query seems to return in a decent amount of time on the old system but on the new box it takes up to 18 minutes to run the query in SSMS.此查询在旧系统上似乎在相当长的时间内返回,但在新机器上,在 SSMS 中运行查询最多需要 18 分钟。 Sometimes if I run it it will generate an XML link and if I click on it to view the XML its throwing a 'System.OutOfMemoryException' and suggests increasing the number of characters retrieved from the server for XML data.有时,如果我运行它,它会生成一个 XML 链接,如果我点击它查看 XML,它会抛出一个“System.OutOfMemoryException”并建议增加从服务器检索到的 Z3501BB093D36CFED3F8B 的字符数。 I increased the option to unlimited and still getting error.我将选项增加到无限制,但仍然出现错误。

The table itself contains 220,500 rows but the query rows returned is showing 129,810 before query stops.该表本身包含 220,500 行,但在查询停止之前返回的查询行显示为 129,810。 Is this simply a matter of not having enough memory available to the system?这仅仅是系统没有足够的 memory 可用的问题吗? This box has 48 GB (Win 2008 R2 EE x64), instance capped to 18GB because its shared dev environment.这个盒子有 48 GB(Win 2008 R2 EE x64),实例上限为 18 GB,因为它的共享开发环境。 Any help/insight would be greatly appreciated as I don't really know XML!任何帮助/见解将不胜感激,因为我并不真正了解 XML!

When you are using SSMS to do XML queries FOR XML, it will generate all the XML and then put it into the grid and allow you to click on it.当你使用SSMS做XML查询FOR XML时,它会生成所有的XML,然后放到网格中让你点击它。 There are limits to how much data it brings back and with 220,000 rows, depending on how wide the table is, is huge and produces a lot of text.它带回的数据量有限制,有 220,000 行,具体取决于表的宽度、巨大并产生大量文本。

The out of memory is the fact that SQL Server is trying to parse all of it and that is a lot of memory consumption for SSMS. memory 的原因是 SQL 服务器正在尝试解析所有这些,这是 SSMS 的大量 memory 消耗。

You can try to execute to a file and see what you get for size.您可以尝试执行到文件并查看大小。 But the major reason for running out of memory, is because that is a lot of XML and returning it to the grid, you will not get all the results all the time with this type of result set (size wise).但是用完 memory 的主要原因是因为有很多 XML 并将其返回到网格中,使用这种类型的结果集(大小明智),您不会一直得到所有结果。

DBADuck (Ben) DBADuck(本)

The out of memory exception you're hitting is due to the amount of text a .net grid control can handle.您遇到的 memory 异常是由于 .net 网格控件可以处理的文本量所致。 220k lines is huge. 220k 行是巨大的。 the setting in SSMS to show unlimited data is only as good as the .net control memory cap. SSMS 中显示无限数据的设置仅与 .net 控制 memory 上限一样好。

You coul look at removing the ELEMENTS option and look at the data in attribute format.您可以查看删除 ELEMENTS 选项并查看属性格式的数据。 That will decreate the amount XML "string space" returned.这将减少 XML “字符串空间”返回的数量。 Personally, I prefer attributes over elements for that reason alone.就个人而言,仅出于这个原因,我更喜欢属性而不是元素。 Context is king, so it depends on what you're trying to accomplish (look at the data or use the data).上下文为王,所以这取决于您要完成的工作(查看数据或使用数据)。 Could youp pipe the data into an XML variable?你可以将 pipe 数据放入 XML 变量中吗? When all is said & done, DBADuck is 100% correct in his statement.总而言之,DBADuck 在他的陈述中是 100% 正确的。

SqlNightOwl SqlNightOwl

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

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