【问题标题】:Selective XML indexing in SQL ServerSQL Server 中的选择性 XML 索引
【发布时间】:2014-04-17 19:35:19
【问题描述】:

我有一个包含数千行的表,在名为 OldValue 的列中包含以下数据:

<attendance xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <CalendarId>100</CalendarId>
  <PeriodId>1019</PeriodId>
  <PersonId>10457</PersonId>
  <Date>2012-01-04 00:00:00</Date>
  <ExcuseId>884</ExcuseId>
</attendance>

我正在尝试设置选择性 xml 索引。这是我到目前为止所做的:

创建选择性 XML 索引:

CREATE SELECTIVE XML INDEX sxi_Test ON [dbo].[mytable](OldValue)
WITH XMLNAMESPACES ('http://www.w3.org/2001/XMLSchema-instance' as yming)
FOR
(    
pathWH2 = '/yming:Attendance/PersonId' AS XQUERY 'xs:string' SINGLETON
);
GO

查询索引总是返回0行:

WITH XMLNAMESPACES ('http://www.w3.org/2001/XMLSchema-instance' as yming)
SELECT COUNT(*)
FROM mytable
WHERE OldValue.exist(N'(/yming:Attendance/yming:PersonId[.=10457])') = 1
GO

有什么建议吗?谢谢。

【问题讨论】:

    标签: sql sql-server xml indexing


    【解决方案1】:

    我通常会偶然发现一个解决方案,其中包含 SQL 中涉及 XML 命名空间的任何内容,但这似乎对我有用:

    DECLARE @x XML = '<attendance xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <CalendarId>100</CalendarId> <PeriodId>1019</PeriodId> <PersonId>10457</PersonId> <Date>2012-01-04 00:00:00</Date> <ExcuseId>884</ExcuseId> </attendance>';
    
    WITH XMLNAMESPACES ('http://www.w3.org/2001/XMLSchema-instance' as yming)
    SELECT @x.exist(N'(/attendance/PersonId[.=10457])')
    GO
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-17
      • 2011-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多