[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XPath Expressions: Separate predicates or one pre

Subject: Re: XPath Expressions: Separate predicates or one predicate with AND?
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 22 Feb 2017 10:13:29 -0000
Re:  XPath Expressions: Separate predicates or one  pre
> On 22 Feb 2017, at 00:10, Dimitre Novatchev dnovatchev@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>> But it occurs to me that in this case the expressions are functionally
identical: the set of predicates is effectively an AND group.
>
>> Is there any reason to prefer one form expression over the other?
>
> No, but the ordering of the sub-expressions (assuming the processor
> does shortcuts) can be really important. That is, place first the
> sub-expression that most-often would make the whole expression false()
> (in case of "and"-ing) or true() (in case of "or"-ing).

Technically, they should probably be ordered by the value of C*P where C is
the cost of evaluation and P is the probability of being false.
>
> I believe that shortcutting isn't specified as mandatory in the XPath
> specifications, but I might be wrong. Certainly, any serious optimizer
> will do shortcutting.
>

XPath 1.0 (in effect) mandates short-cutting, XPath 2.0 and later do not.
That's because the XML database people thought it important to allow
optimizers to evaluate the conditions in any order, for example to take
advantage of indexes.

Saxon will in fact do some re-ordering of predicates on occasions. It can't
assess the probability of a predicate returning false, but it does crudely
estimate the cost of evaluation of each predicate, and will try to evaluate
the cheapest predicates first. This is done after normalizing X[Y][Z] and X[Y
and Z] to a common representation (all assuming of course that the predicates
are non-positional).

Michael Kay
Saxonica

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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

Buy Stylus Studio Now

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-2013 All Rights Reserved.