[Bug 4980] Optimization rules

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

           Summary: Optimization rules
           Product: XPath / XQuery / XSLT
           Version: Working drafts
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XQuery
        AssignedTo: chamberl@almaden.ibm.com
        ReportedBy: oliver@cbcl.co.uk
         QAContact: public-qt-comments@w3.org


I am a bit confused as to what optimizations are permitted by the spec.

Could, for example,

let $x = codepoints-to-string(12)
return $x = $x

be legitimately optimized down to true(), despite the fact that
codepoints-to-string(12) should throw an FOCH0001 error?

Section 2.3.4 of the spec says:
"Consider an expression Q that has an operand (sub-expression) E. In general
the value of E is a sequence. At an intermediate stage during evaluation of the
sequence, some of its items will be known and others will be unknown. If, at
such an intermediate stage of evaluation, a processor is able to establish that
there are only two possible outcomes of evaluating Q, namely the value V or an
error, then the processor may deliver the result V without evaluating further
items in the operand E."

which seems to imply the above optimization is fine.
If this is correct then could the following expression be optimised down to
true() as well (which is clearly not the intention of the query)?

typeswitch(.)
case $a as xs:integer return true()
default return error()

Received on Thursday, 23 August 2007 14:52:13 UTC