performance on xml column in sql server -
i have normalized tables keep data in following format.
first table name logbook columns journeyid, locationid, positionid, id,
second table logbookevents columns logbookid, lifecodeid, lifecode, lifecodevalue, totalvalue
the first table has 3.4 million records , second table has 17.3 million records.
i found performance on these tables big heavy have necessary indexes on tables.
therefore have designed new table has xml format
new table is.. logbooklifecodes, columns journeyid, lifecode (xml type)
by doing this, have reduced number of records 900,000
and lifecode hold data in following format
<logbooklifecodeevents><lifecodes> <logbookid>11</logbookid> <locationid>0</locationid> <positionid>0</positionid> <lifecodeid>4</lifecodeid> <lifecode>fh</lifecode> <lifevalue>0.0000</lifevalue> <lifetotal>0.0000</lifetotal>
and using following query return data in table format.
select tbl.col.value('logbookid[1]', 'int'), tbl.col.value('locationid[1]', 'int'), tbl.col.value('locationpositionid[1]', 'int'), tbl.col.value('lifecodeid[1]', 'int'), tbl.col.value('lifecode[1]', 'varchar(20)') logbooklifecodes outer apply logbooklifecodes.lifecode.nodes('//logbooklifecodeevents/lifecodes') tbl(col) tbl.col.value('logbookid[1]', 'int') = 11
however query takes 4 mins run value logbookid = 11, not acceptable, returning 130,000 records.
but if query above-normalized tables takes 01 seconds, same number of records
the xml columns on second table having indexes, primary , secondary.
when check execution plan, normalized table index (clustered) cost 73%
but on xml column index cost 45 %
just know, using xml column rather using relational tables better ? or other way improve performance of xml column second table has less records compare first structure ?
appreciate commends , advices
many
Comments
Post a Comment