Sql-server – SQL Server xml performance

performancesql serversql-server-2008-r2xml

I have a table with 21 columns. The majority are numerical and the rest are nvarchar.

I need to add 4 columns that will contain XML data for each row. The XML data for each row can be anywhere from 200 to 2,000 lines.

The question is:

  • Does adding the XML typed columns to the same table change the speed of querying that table?

  • What are the performance benefits when I add the xml typed columns to another table and join both tables when doing queries?

  • Is it better to encode the XML data to shrink it and decode it in the application?

Best Answer

Increasing the size of a table will always have a negative impact on performance. So adding XML columns will have a negative impact.

Splitting the tables will result in more flexibility as you will not always shuffle between the xmls.

That depends on your need to browse and use the xmls on the server side. SQL does not keep the xml in the database as a string (nvarchar) but in an optimized form. If you do not need to use it as it is in tsql then you will not need to keep it as an XML datatype so that means you can compress it as you want and keep it even binary.