Re: [bdbxml] "Pure" XPath2 versus XQuery
George Feinberg <[email protected]> Tue, 21 Feb 2006 17:35:53 -0500
| Newsgroups | gmane.comp.db.dbxml.general |
|---|---|
| Message-ID | <[email protected]> |
Kiril, The query optimizer works on both XPath and XQuery expressions, as you've seen. There are, however, some cases where it can get tripped up by one or the other. These cases are being addressed with continual improvements in the optimizer. In general, as long as the correct indexes are used, based on the query plan output, XQuery vs XPath should perform about the same. You should, however, make sure that the query plans are using expected indexes. Using XPath when possible is a reasonable rule of thumb, as the expressions are often more compact. But, as John recently pointed out, it can sometimes be better to use simpler expressions (e.g. variables) in predicates, which may argue for XQuery. Again, the best results are obtained through experimentation. It's worth mentioning that for repeated queries, a very large benefit is realized by pre-parsing an expression into XmlQueryExpression, and reusing that object. Regards, George > Hi all, > > I wonder if there is performance difference (or other pros and > cons) when executing simple queries as XPath or XQuery. > Example: > > /Item[@type='Mail' and days-from-duration(fn:current-date()-xs:date > (/Item/CreationTime)) <= 7] > > versus > > for $x in /Item[@type='Mail'] > where days-from-duration(fn:current-date()-xs:date($x/ > CreationTime)) <= 5 > return $x > > I examined the query plans and they both seem almost same... > Well, this is a simple example, but should I always prefer XPath, > if it does the job? > > TIA, > > Kiril. > ------------------------------------------ To remove yourself from this list, send an email to [email protected]