[Bug 2708] Errors and Optimization and Cardinality checks

http://www.w3.org/Bugs/Public/show_bug.cgi?id=2708

           Summary: Errors and Optimization and Cardinality checks
           Product: XPath / XQuery / XSLT
           Version: Candidate Recommendation
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XPath
        AssignedTo: chamberl@almaden.ibm.com
        ReportedBy: mike@saxonica.com
         QAContact: public-qt-comments@w3.org


Section 2.3.4 says:

"Another consequence of these rules is that where none of the items in a
sequence contributes to the result of an expression, the processor is not
obliged to evaluate any part of the sequence. Again, however, the processor
cannot dispense with a required cardinality check: if an empty sequence is not
permitted in the relevant context, then the processor must ensure that the
operand is not an empty sequence."

It's not clear quite how much checking this requires.

Consider

(1,2,3) = (1,2,exactly-one(//title))

//title is not allowed to return an empty sequence. Does this mean we are
required to evaluate it and check it? I think we would agree that it does not.
In other words, the requirement to do cardinality checking does not cascade.

Now consider

max((), resolve-uri($collation, 'http://base/'))

Does the quoted paragraph mean that I am required to determine that the
collation is not (), even though the result of the max() function is clearly (),
regardless of the actual collation? It seems to me that the wording of the above
paragraph says that this is indeed required. If that's the case, it seems wrong:
it's a quite unnecessary constraint on the way the processor operates. Whether
the decision is made statically or dynamically, we should always have the
freedom to avoid evaluating an expression if its value is not needed.

Perhaps we could use a form of words such as: if an expression is evaluated
(wholly or in part), then it must be evaluated sufficiently to ensure that any
cardinality constraints on the value of the expression are satisfied.

Michael Kay

Received on Wednesday, 11 January 2006 21:55:05 UTC