user3765179
user3765179

Reputation: 1

eXist db index not used in xquery

I have stored in my eXist db nodes of the following type:

<Order ID="170473" LnkID="8288374995" OrignDt="2003-07-08" TrdDt="2003-07-09" Acct="104158163" AcctIDSrc="99" DayBkngInst="ingrated" BkngUnit="hobbyhorse" SettlDt="2003-07-28" ClrFeeInd="B" HandlInst="3" MinQty="2088.58" ProcCode="1" Side="2"
LocReqd="N" TxnTm="2003-07-06T08:44:24" QtyTyp="0" Typ="A" PxTyp="4" Px="4258.33" Ccy="USD" SolFlag="N" IOIID="8596226323" ExpireDt="2003-06-19" GTBkngInst="2" Cpcty="A" Rstctions="A" CustCpcty="1660" ForexReq="Y" SettlCcy="inclination" Txt="eats" EncTxt="pendulous" Qty2="4028.86" MaxShow="1636.80" CxllationRights="M" MnyLaunderingStat="N" Designation="tied" >
<Hdr SID="997453497" D2ID="5969180787" SSub="swiftest" D2Sub="flay" PosDup="N" Snt="2003-10-24T12:13:50" OrigSnt="2003-07-19T00:23:46" MsgEncd="lechery" ><Hop ID="9148044310" Ref="33787" Snt="2003-08-24T21:26:11"></Hop>
</Hdr><Pty ID="8059449011" Src="H" ><Sub ID="228" ></Sub></Pty>
<Instrmt Sym="VRTS" Sfx="CD" ID="8962619773" Src="5" CFI="entrances" MatDt="2003-12-09" CpnPmt="2004-06-12" Issued="2004-05-14" RepoTrm="2749" CrdRtg="dad" IssuCtry="purpose" Redeem="2003-10-17" Strk="2028.23" StrkCcy="posterns" Exch="religiously" EncSecDescLen="4238" Pool="separation" IntAcrl="2003-08-17" ></Instrmt>
<OrdQty Qty="3652" Cash="3036.44" Pct="3882.34" RndDir="2" RndMod="1819.70" ></OrdQty>
</Order>

I would like to have an index for the ID attribute. My configuration file is:

   <collection xmlns="http://exist-db.org/collection-config/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<index>
    <create qname="@ID" type="xs:string"/>
</index>
<triggers>
    <trigger class="org.exist.extensions.exquery.restxq.impl.RestXqTrigger"/>
</triggers>

The index I have created is only used in pure xpath queries, such as

//Order[@ID ="170475"]

but not in xquery queries such as:

for $ord in//Order/@ID
where $ord = "150985"
return $ord

Is there any way to fix this?

Upvotes: 0

Views: 136

Answers (2)

Wolfgang Meier
Wolfgang Meier

Reputation: 101

Please try to change your query into

for $ord in//Order
where $ord/@ID = "150985"
return $ord

The query engine tries to rewrite your expression in order to use the index. It will fail analyzing your previous formulation, but should succeed on the one above.

The general recommendation is to use XPath statements with filters where possible, because they are easier to rewrite automatically.

Upvotes: 1

DiZzZz
DiZzZz

Reputation: 656

It is documented that the eXist-db xquery processor has difficulties to optimize queries with the where clause.

Although your second query is syntactically correct, it is recommended to use the XPATH equivalent.

Upvotes: 0

Related Questions