xsl-list
[Top] [All Lists]

Re: [xsl] XPath Expressions: Separate predicates or one predicate with AND?

2017-02-22 04:13:35

On 22 Feb 2017, at 00:10, Dimitre Novatchev dnovatchev(_at_)gmail(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> 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
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>