如需了解更多详情,请在谷歌搜索Structured Component to an XMLIndex Index。
还有这里的小例子。
1)准备测试结构。
create table xindex_example(a number, b xmltype);
insert into xindex_example values(1,xmltype('<root><x>
<a>1</a>
<b>2</b>
</x>
</root>'));
2) 使用参数创建 xmlindex。
CREATE INDEX xindex_example_idx ON xindex_example (b) INDEXTYPE IS XDB.XMLIndex
PARAMETERS (q'~XMLTable my_test_group_tab
'/root/x'
columns a_val number path './a' , b_val number path './b'~');
;
Oracale 会自动创建表 my_test_group_tab,但您不能直接从该表进行查询。 (ORA-30967: operation directly on the Path Table is disallowed)
您可以执行 desc my_test_group_tab 来查看结构。
3) 在create table上创建b+tree索引
create index my_test_group_tab_idx on my_test_group_tab(a_val);
4) 并测试它。
select * from (
select x.* from xindex_example,xmltable('/root/x' passing b columns a_val number path './a' , b_val number path './b') x)
where a_val=1;
5) 执行计划:
-----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 50 | 3 (0)| 00:00:01 |
| 1 | NESTED LOOPS | | 1 | 50 | 3 (0)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| MY_TEST_GROUP_TAB | 1 | 38 | 2 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | MY_TEST_GROUP_TAB_IDX | 1 | | 1 (0)| 00:00:01 |
| 4 | TABLE ACCESS BY USER ROWID | XINDEX_EXAMPLE | 1 | 12 | 1 (0)| 00:00:01 |
------------------------------------------------------------------------------------------------------