我正在为 xmltype 列使用结构化存储类型。我正在尝试在属性上创建索引,但不知何故,Oracle 没有获取索引并进行全表扫描。我已经检查了http://docs.oracle.com/cd/B28359_01/appdev.111/b28369/xdb_indexing.htm#CHDCJIJB上的文档,但它没有给出在属性上创建索引的示例。有人可以给我一个在属性上创建 xml 索引的例子吗?
谢谢凯文
我正在为 xmltype 列使用结构化存储类型。我正在尝试在属性上创建索引,但不知何故,Oracle 没有获取索引并进行全表扫描。我已经检查了http://docs.oracle.com/cd/B28359_01/appdev.111/b28369/xdb_indexing.htm#CHDCJIJB上的文档,但它没有给出在属性上创建索引的示例。有人可以给我一个在属性上创建 xml 索引的例子吗?
谢谢凯文
你需要在这里显示一些代码。
xmlindex
这是在属性(及其后代节点)上创建的示例:
SQL> create table xmltest ( a xmltype);
Table created.
SQL> insert into xmltest values ('<root>
2 <a test="foo" test2="asd">
3 <b>hi</b>
4 </a>
5 <a test="foo2" test2="asd2">hi</a>
6 </root>');
1 row created.
SQL> commit;
Commit complete.
SQL> create index test_xmlindex on xmltest (a)
2 indextype is XDB.XMLIndex
3 parameters ('paths (include (/root/a/@test))');
Index created.
SQL> set pagesize 100 lines 200 heading off
SQL> explain plan for select * from xmltest where xmlexists('/root/a[@test="foo"]' passing a);
Explained.
SQL> select * from table(dbms_xplan.display());
Plan hash value: 2925043098
-------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2026 | 6 (17)| 00:00:01 |
| 1 | NESTED LOOPS | | 1 | 2026 | 6 (17)| 00:00:01 |
| 2 | VIEW | VW_SQ_1 | 1 | 12 | 4 (0)| 00:00:01 |
| 3 | HASH UNIQUE | | 1 | 5046 | | |
| 4 | NESTED LOOPS | | | | | |
| 5 | NESTED LOOPS | | 1 | 5046 | 4 (0)| 00:00:01 |
|* 6 | TABLE ACCESS BY INDEX ROWID| SYS82641_TEST_XMLIN_PATH_TABLE | 1 | 3524 | 2 (0)| 00:00:01 |
|* 7 | INDEX RANGE SCAN | SYS82641_TEST_XMLIN_VALUE_IX | 1 | | 1 (0)| 00:00:01 |
|* 8 | INDEX RANGE SCAN | SYS82641_TEST_XMLIN_PIKEY_IX | 1 | | 1 (0)| 00:00:01 |
|* 9 | TABLE ACCESS BY INDEX ROWID | SYS82641_TEST_XMLIN_PATH_TABLE | 1 | 1522 | 2 (0)| 00:00:01 |
| 10 | TABLE ACCESS BY USER ROWID | XMLTEST | 1 | 2014 | 1 (0)| 00:00:01 |
-------------------------------------------------------------------------------------------------------------------
by indexing paths (include (/root/a/@test))
it would contain the child <b>
node in the index but not the test2
attribute. ommitting /@test
would have the index pick up the test2
attribute as well.