CREATE SELECTIVE XML INDEX
Creates a new selective XML index on the specified table and XML column.
Selective XML indexes improve the performance of XML indexing and querying by indexing only the subset of nodes that you typically query.
For more information, see the following topics:
You can also create secondary selective XML indexes. For information, see Create, Alter, and Drop Secondary Selective XML Indexes.
CREATE SELECTIVE XML INDEX index_name
ON <table_object> (<xml_column_name>)
[WITH XMLNAMESPACES (<xmlnamespace_list>)]
FOR (<promoted_node_path_list>)
[WITH (<index_options>)]
<table_object> ::= { [ database_name. [ schema_name ] . | schema_name. ] table_name }
<promoted_node_path_list> ::= <named_promoted_node_path_item> [, <promoted_node_path_list>]
<named_promoted_node_path_item> ::= <path_name> = <promoted_node_path_item>
<promoted_node_path_item>::=<xquery_node_path_item> | <sql_values_node_path_item>
<xquery_node_path_item> ::= <node_path> [as XQUERY <xsd_type_or_node_hint>] [SINGLETON]
<xsd_type_or_node_hint> ::= [<xsd_type>] [MAXLENGTH(x)] | node()
<sql_values_node_path_item> ::= <node_path> as SQL <sql_type> [SINGLETON]
<node_path> ::= <character_string_literal>
<xsd_type> ::= <character_string_literal>
<sql_type> ::= <identifier>
<path_name> ::= <identifier>
<xmlnamespace_list> ::= <xmlnamespace_item> [, <xmlnamespace_list>]
<xmlnamespace_item> ::= <xmlnamespace_uri> AS <xmlnamespace_prefix>
<xml_namespace_uri> ::= <character_string_literal>
<xml_namespace_prefix> ::= <identifier>
<index_options> ::= (
| PAD_INDEX = { ON | OFF }
| FILLFACTOR = fillfactor
| SORT_IN_TEMPDB = { ON | OFF }
| IGNORE_DUP_KEY =OFF
| DROP_EXISTING = { ON | OFF }
| ONLINE =OFF
| ALLOW_ROW_LOCKS = { ON | OFF }
| ALLOW_PAGE_LOCKS = { ON | OFF }
| MAXDOP = max_degree_of_parallelism
)
CREATE clause
For example: CREATE SELECTIVE XML INDEX sxi_index
ON clause
For example: ON Tbl(xmlcol)
WITH XMLNAMESPACES clause
For example: WITH XMLNAMESPACES ('http://www.tempuri.org/' as myns)
FOR clause
For example:
FOR(
pathab = '/a/b' as XQUERY 'node()'
pathabc = '/a/b/c' as XQUERY 'xs:double',
pathdtext = '/a/b/d/text()' as XQUERY 'xs:string' MAXLENGTH(200) SINGLETON
pathabe = '/a/b/e' as SQL NVARCHAR(100)
)
WITH clause
Create a selective XML index instead of an ordinary XML index in most cases for better performance and more efficient storage. However, a selective XML index is not recommended when either of the following conditions is true:
-
You need to map a large number of node paths.
-
You need to support queries for unknown elements or elements in an unknown location.
For information about limitations and restrictions, see Selective XML Indexes (SXI).
The following example shows the syntax for creating a selective XML index. It also shows several variations of the syntax for describing the paths to be indexed, with optional optimization hints.
CREATE SELECTIVE XML INDEX sxi_index
ON Tbl(xmlcol)
FOR(
pathab = '/a/b' as XQUERY 'node()'
pathabc = '/a/b/c' as XQUERY 'xs:double',
pathdtext = '/a/b/d/text()' as XQUERY 'xs:string' MAXLENGTH(200) SINGLETON
pathabe = '/a/b/e' as SQL NVARCHAR(100)
)
The following example includes a WITH XMLNAMESPACES clause.
CREATE SELECTIVE XML INDEX on T1(C1)
WITH XMLNAMESPACES ('http://www.tempuri.org/' as myns)
FOR ( path1 = '/myns:book/myns:author/text()' )
