Best Practices from Oracle Development's A‑Team

Improving XQuery performance

Mark Nelson


XQuery transformations are often used in pipelines in Oracle Service Bus to perform data transformation.  Performance of XQuery transformations is a key area to focus on when performance tuning an Oracle Service Bus environment.

Main Article

During performance testing of your project you should use the activity timing metrics to identify any XQuery performance issues and optimize those queries for better performance.  The recommended approach is to measure the average time taken to run each query, then multiply this by the number of times you expect that query to be used over some defined time period, e.g. one hour.  The results should be sorted from largest to smallest.  You should start at the top of the list and optimize as many of the queries as necessary to obtain the necessary performance.  You should only optimize the queries if there is likely to be a significant performance gain.  Optimization of the queries should be done by looking for opportunities to reorder or modify the statements in order to obtain faster execution.

XQuery performance should be tested with large payloads whenever possible, or at least with many invocations of the same transformation and results averaged.

Some general quidelines for improving the performance of XQuery transformations are as follows:

  • Avoid the use of double slashes (“//”) at the beginning of XPath expressions.  They should only be used if the exact location of a node is not known at design time.  Use of “//” will force the entire payload to be read and parsed.
  • Index XPath expressions where applicable.  For example, if you know that there is only one “Order” and only one “Address” then using an XPath expression like “$body/Order[1]/Address[1]” instead of “$body/Order/Address” will minimize the amount of the payload that needs to be parsed.  Do not use this approach if the expected return value is a list of nodes.
  • Extract frequently used parts of a large XML document as intermediate variables.  This will consume more memory, but will reduce redundant XPath processing.  For example:
    let $customer := $body/Order[1]/CustomerInfo[1]
    $customer/ID, $customer/Status

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha

Recent Content