DooDoo
DooDoo

Reputation: 13437

SELECT XML fields with best performance in sql server

what is a good solution for get best performance of SELECTing XML fields?Cosider a table with 100000 record.If I select all table content and create a table variable and then create index on it and then calculate values on it ? or create several index on my xml field and then calculate values?

If any one has better solution please say.

thanks

Upvotes: 0

Views: 254

Answers (1)

marc_s
marc_s

Reputation: 754268

If you need to extract only certain single values from your XML, you could also investigate this approach:

  • define a stored function that takes your XML as input parameter, and extracts whatever you need to extract from it, and returns an INT or a VARCHAR or something
  • define a computed, persisted column on your base table (where your XML is stored) that calls this function

Once you have a computed, persisted column, you can easily index that column.

Unfortunately, this only works if you need to extract a single piece of information from your XML column - it doesn't work if you need to extract an entire list of values from the XML

If you need to extract lists of information, then your only real option would be XML indices. In our experience, though - the overhead (in terms of disk space) is extremely high - a database we had went from about 2 GB to over 10 GB when we added a single XML index....... it's an option and you could try it - but be aware of the potential downsides, too.

Upvotes: 3

Related Questions