[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

Re: [x-query-talk] trying to optimize xpath expression

Frans Englich frans.englich at telia.com
Sat Aug 26 13:09:24 PDT 2006


xpath performance improve
On Friday 25 August 2006 20:34, Enric Jaen wrote:
> (Sorry if you receive this mail duplicated)
>
> Hi all,
>
> I'd like to improve the performance of the following simple xpath
> expression, used inside this simple XQuery function:
>
> declare function foo($input as node()) as item()+ {
>  for $elem in $input//EEE/FFF
>  return $elem
> };

First of all you can skip the for/return clause. I believe Saxon removes it 
all together, but for other implementations it can be an improvement. That 
is, the function can be:

declare function foo($input as node()) as item()+
{
	$input//EEE/FFF
};

It also looks like that the return type can be stricter. That is, element()+ 
instead of item()+.


>  I know that the input document has an structure like:
>
> <AAA>
>   <BBB>
>     <CCC>
>        <DDD>
>           <EEE>
> 	     <FFF>
> 	  <EEE>
> 	     <FFF>
> 	  <EEE>
> 	     <FFF>
> 	  ...
>       </DDD>
>     </CCC>
>   </BBB>
> </AAA>
>
> The names of  AAA, BBB, CCC, and DDD are unknown.
>
>
> I have tried changing the expression $input//EEE/FFF to:
>
> $input/*/*/*/*/EEE/FFF
>
> which I think it should perform better because the lack of the '//' path 
> (please correct me if I am wrong), however the time consumed is very
> similar.
>
> Similarly is happening with an XQuery function that performs:
> $input//EEE[FFF=$FFF]/FFF
>
> which I have changed it to:
> $input/*/*/*/*/EEE/[FFF=$FFF]FFF
>
> but the improvement is not that better.
>
> I am using saxonB8.7.3, and I am calling the XQuery function from Java. I
> am trying with 1000 <EEE> elements. The function is compiled into an
> XQueryExpression before to invoke the UserFunction.call method. The input
> document is a DocumentWrapper object.
>
> I wonder if there is something I can do to improve the performance of the
> Xpath expression?

I don't know if this holds for your input data(the above example snippet isn't 
well-formed, for example), but nevertheless:

$input/AAA[1]/BBB[1]/CCC[1]/DDD[1]/EEE/FFF

or simply

$input/AAA/BBB/CCC/DDD/EEE/FFF


Cheers,

		Frans


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.