Re: [bdbxml] indeces are not used in LET clauses of a FLWOR expression

John Snelson <[email protected]>
Newsgroups gmane.comp.db.dbxml.general
Message-ID <[email protected]>
The problem here is that the $f1 variable is only read inside the 
fn:count() function. It is a known deficiency of the query planner that 
certain functions (especially ones which do not return nodes) inhibit 
the use of indexes. This should behave better in the 2.2 release, 
intended for Q3 this year.

Can I suggest that you modify your query to look like this:

for $p in collection('mydb.db')//XMI.Content
let $r := $p//SSL.Core.ServiceProfile/@name[. = 'TaxiReservation']
where $r
return <group><id>{dbxml:metadata('id', 
$p)}</id><rank>{count($r)}</rank></group>

Also, I noticed that you were using the wrong slashes in 
"collection('mydb.db')\\XMI.Content". You need to use forward slashes in 
a path expression.

I hope this helps,

John

George Kotopoulos wrote:
> 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]
> 



------------------------------------------
To remove yourself from this list, send an
email to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.