Forum Stats

  • 3,781,633 Users
  • 2,254,532 Discussions


Newbie question on indexing XML type

user614224 Member Posts: 62 Blue Ribbon
edited Nov 4, 2009 3:24PM in General XML
I cannot get a query to use an index I created for an XML type. Here is my setup:

create table XmlTest( id number,
data_xml XMLType)
XmlType data_xml STORE AS CLOB;

I inserted 10,000 records like this ( each record has a unique id):

insert into XmlTest(id, data_xml) values
( 1
, XMLType('<company>

I then created this index:

ON xmltest (extractValue(data_xml, '/company/department/id'));

When I run this query, it takes a long time - 12 seconds.

SELECT id from xmltest
WHERE EXISTSNODE( data_xml, '/company/department[id="37500"= 1;

it is doing a full table scan. What is wrong with my index?



  • Jason_(A_Non)
    Jason_(A_Non) Member Posts: 2,058 Silver Trophy
    I've yet to have the opportunity to work with indexes on XML data but I suspect it is because your index alone cannot satisfy the results of the query and the data you want is from every row in the table so a FTS is the best approach.

    To restate, you are asking for the id value from the table where the XML contains a certain node. This node exists in every entry in the index, so why use the index if you have to go get data from the table.

    Or it is because EXISTSNODE is checking for a different condition then your index was defined on. I suspect if you do something like /company/department/id[. = '10'] in your EXISTSNODE, it should use the index.

    All this is a guess and the best place for you to look is the {forum:id=34} forum and also [Marco&apos;s Blog|]
This discussion has been closed.