Skip to Main Content

Berkeley DB Family

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XQuery performance very slow

591630Aug 16 2007 — edited Aug 29 2007
Hello,

I have to query one document with a lot of similar elements.
Elements can have relationships among each other defined by a link between "id" and "href" attributes.

<ele1 id="0815">
<ele2>
<ele3 href="1234" />
</ele2>
<name>
<string>a name</string>
</name>
</ele1>
....
<ele1 id="5678">
<ele2>
<ele3 href="0815" />
</ele2>
<name>
<string>another name</string>
<scope>...</scope>
</name>
</ele1>
....


At the end there should for every "ele1" element following result row:
<result topic_id="5678" type_id="0815" topic_name="another name" type_name="a name" />

I tried to archive this by following XQuery:
declare function local:getName($id as xs:string) as xs:string
{
let $a := doc("doc.xml")/ele1[@id = $id]
let $not_scoped := $ele1/name/(if (not(scope)) then string else())

(: if we have "name" without "scope" element print this else print first "scope" :)
return if($not_scoped[1])
then string($not_scoped[1])
else (string($ele1/name[scope][1]/string))
};

for $topic in doc("doc.xml")/ele1[ele2/ele3]
let $topic_id := $ele1/@id

return <result topic_id='{$topic_id}' tpoic_name='{local:getName($topic_id)}' type_id='{$type_id}' type_name='{local:getName($type_id)}' />


The performance bottleneck is following part from "getName" function:
let $a := doc("doc.xml")/ele1[@id = $id]

It takes up to 60% of query time and pushes my query execution time behind 20sec for my test document.

Can anyone give my a hint or advice to optimize my query and boost execution time?

Thank you.


With kind regards,

squig
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 26 2007
Added on Aug 16 2007
12 comments
1,576 views