cross apply xml query performs exponentially worse as xml document grows

前端 未结 2 778
南方客
南方客 2020-11-29 10:41

What I Have

I have a variable size XML document that needs to be parsed on MSSQL 2008 R2 that looks like this:



        
2条回答
  •  抹茶落季
    2020-11-29 10:44

    Adding an XML index did the trick. Now the 6,500 records that took 20 minutes to run takes < 4 seconds.

    create table #temp (id int primary key, x xml)
    create primary xml index idx_x on #temp (x)
    
    insert into #temp (id, x)
    values (1, '
    
      
        0.506543009706267
        -0.79500402346138
        0.0152649050024924
      
      
        0.366096802804087
        -0.386642801354842
        0.031671174184115
      
      
        0.883962036959074
        -0.781459993268713
        0.228442351572923
      
    
    ')
    
    select c.value('(../@name)','varchar(5)') as item_name
          ,c.value('(@id)','uniqueidentifier') as field_id
          ,c.value('(@type)','int') as field_type
          ,c.value('(.)','nvarchar(15)') as field_value
    from   #temp cross apply
           #temp.x.nodes('/data/item/field') as y(c)
    
    drop table #temp
    

提交回复
热议问题