Hi Constantine, > for $a in (db:open('DB1')/item/order-id) > return > if (db:open('DB2')//order-id[. = $a]) then > $a > else > ()
Do some of the order-id elements contain descendant elements? db:open('DB1')/item/order-id[*] If yes, the following query might be faster: for $a in (db:open('DB1')/item/order-id) return if (db:open('DB2')//order-id[text() = $a]) then $a else () Here is another way to rewrite the query: for $a in (db:open('DB1')/item/order-id) where db:open('DB2')//order-id[text() = $a] return $a > > > Note that the optimized query uses db:open-pre to access DB2. When I > re-write the query myself to use the TEXT index then performance is > excellent. But why such a difference? > > > > > > Query 2 [returns in 0.3 second] > > ---------------------------------------- > > > > for $a in (db:open('DB1')/item/order-id) > > return > > if (db:text('DB2', $a)/parent::order-id) then > > $a > > else > > () > > > ________________________________ > > Elsevier B.V. Registered Office: Radarweg 29, 1043 NX Amsterdam, The > Netherlands, Registration No. 33156677, Registered in The Netherlands.