Re: [bdbxml] indeces are not used in LET clauses of a FLWOR expression
George Kotopoulos <gkoto-taE2apzES20Cep0kKqy/[email protected]>
| Newsgroups | gmane.comp.db.dbxml.general |
|---|---|
| Message-ID | <[email protected]> |
John Snelson <jsnelson@...> writes:
>
> Indexes are indeed used in let and return statements. You might want to
> read a series of blog entries I have been writing about indexing in DB XML:
>
> http://blog.parthenoncomputing.com/dbxml/archives/discussion/index.html
>
> Also, you can use the "queryplan" comand in the dbxml shell (called
> "dmxml.exe") to look at which indexes would be used during the execution
> of your query.
>
> If you send the query you are using and the output from the "queryplan"
> command to the list, I can help you understand which indexes are being
> used, and why.
>
> John
>
Hi John,
Thanks for the reply.
In fact I used the query planner command to view the query plan.
I used it again but it didn't used the index then the expression was in the Let
clause.
The database has an edge-attribute-equality-string default index
The query looks like this:
for $p in collection('mydb.db')\\XMI.Content
let $f1 := $p//SSL.Core.ServiceProfile/@name[. = 'TaxiReservation'],
$r := if (fn:count($f1) > 0) then 1 else 0
where $r > 0
oder by $r descending
return <group><id> {dbxml:metadata('id' ,$p)} </id><rank>{$r}</rank></group>
I want the index to be used when calculating the $f1 variable.
if I put the expression in the where clase the index is used normally:
(<OQPlan>V(edge-attribute-equality-string,
SSL.Core.ServiceProfile.@name,=,'TaxiReservation')</OQPlan>)
but when I ask for the above query the following query plan is produced:
<XQuery>
<FLWOR>
<ForBinding name="p">
<Navigation>
<QueryPlanFunction result="collection">
<OQPlan>U</OQPlan>
</QueryPlanFunction>
<Step axis="descendant-or-self" uri="*" name="*" nodeType="*"/>
<Step axis="child" name="XMI.content" nodeType="element"/>
</Navigation>
</ForBinding>
<LetBinding name="f1">
<Navigation>
<Variable name="p"/>
<Step axis="descendant-or-self" uri="*" name="*" nodeType="*"/>
<Step axis="child" name="SSL.Core.ServiceProfile" nodeType="element"/>
<Step axis="attribute" name="name" nodeType="attribute">
<Predicates>
<Operator name="equal">
<ContextItem/>
<Sequence>
<AnyAtomicTypeConstructor value="TaxiReservation"
typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
</Sequence>
</Operator>
</Predicates>
</Step>
</Navigation>
</LetBinding>
<LetBinding name="r">
<If>
<Test>
<Operator name="greater_than">
<Function name="{http://www.w3.org/2004/07/xpath-functions}:count">
<Variable name="f1"/>
</Function>
<Sequence>
<AnyAtomicTypeConstructor value="0"
typeuri="http://www.w3.org/2001/XMLSchema" typename="integer"/>
</Sequence>
</Operator>
</Test>
<Then>
<Sequence>
<AnyAtomicTypeConstructor value="1"
typeuri="http://www.w3.org/2001/XMLSchema" typename="integer"/>
</Sequence>
</Then>
<Else>
<Sequence>
<AnyAtomicTypeConstructor value="0"
typeuri="http://www.w3.org/2001/XMLSchema" typename="integer"/>
</Sequence>
</Else>
</If>
<Where>
<Operator name="greater_than">
<Variable name="r"/>
<Sequence>
<AnyAtomicTypeConstructor value="0"
typeuri="http://www.w3.org/2001/XMLSchema" typename="integer"/>
</Sequence>
</Operator>
</Where>
</LetBinding>
<Sort>
<Specification modifier="descending|empty_least">
<Variable name="r"/>
</Specification>
</Sort>
<DOMConstructor type="element">
<Name>
<Sequence>
<AnyAtomicTypeConstructor value="group"
typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
</Sequence>
</Name>
<Children>
<DOMConstructor type="element">
<Name>
<Sequence>
<AnyAtomicTypeConstructor value="docid"
typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
</Sequence>
</Name>
<Children>
<Variable name="p"/>
</Children>
</DOMConstructor>
<DOMConstructor type="element">
<Name>
<Sequence>
<AnyAtomicTypeConstructor value="rank"
typeuri="http://www.w3.org/2001/XMLSchema" typename="string"/>
</Sequence>
</Name>
<Children>
<Variable name="r"/>
</Children>
</DOMConstructor>
</Children>
</DOMConstructor>
</FLWOR>
</XQuery>
So, I guess that no index is used...
If you have any other ideas or recomedations please post.
Thanx in advance
George
------------------------------------------
To remove yourself from this list, send an
email to [email protected]