Why insert-select to variable table from XML variable so slow?

后端 未结 2 1329
难免孤独
难免孤独 2020-12-03 08:09

I\'m trying to insert some data from a XML document into a variable table. What blows my mind is that the same select-into (bulk) runs in no time while insert-select takes a

2条回答
  •  北海茫月
    2020-12-03 08:51

    This is a bug in SQL Server 2008. Use

    insert @columns 
    select ColumnNames.value('.', 'nvarchar(300)') name
    from @xColumns.nodes('/columns/name') T1(ColumnNames)
    OPTION (OPTIMIZE FOR ( @xColumns = NULL ))
    

    This workaround is from an item on the Microsoft Connect Site which also mentions a hotfix for this Eager Spool / XML Reader issue is available (under traceflag 4130).

    The reason for the performance regression is explained in a different connect item

    The spool was introduced due to a general halloween protection logic (that is not needed for the XQuery expressions).

提交回复
热议问题