<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>27392</bug_id>
          
          <creation_ts>2014-11-21 16:07:31 +0000</creation_ts>
          <short_desc>Type checking of functions</short_desc>
          <delta_ts>2014-11-22 10:57:26 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>XQuery 3.1</component>
          <version>Working drafts</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Christian Gruen">christian.gruen</reporter>
          <assigned_to name="Jonathan Robie">jonathan.robie</assigned_to>
          <cc>mike</cc>
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>115299</commentid>
    <comment_count>0</comment_count>
    <who name="Christian Gruen">christian.gruen</who>
    <bug_when>2014-11-21 16:07:31 +0000</bug_when>
    <thetext>Section 2.3.4 Errors and Optimization of the XQuery 3.1 spec says that:

&quot;The effect of these rules is that the processor is free to stop examining further items in a sequence as soon as it can establish that further items would not affect the result except possibly by causing an error. For example, the processor may return true as the result of the expression S1 = S2 as soon as it finds a pair of equal values from the two sequences.&quot;

This is currently specified at the level of expressions, but I have not found a clear hint if it can also be applied to type checks.

See the following example:

  function() as xs:integer+ { 1 to 100000, &lt;x/&gt; }() = 1

This query could be rewritten to (something similar like) the following expression, and it would yield true (provided that a processor evaluates the query in a streaming manner):

  (1 to 100000, &lt;x/&gt;) ! (. treat as xs:integer) = 1

Another example: Strict type checks would prevent a query processor from streaming results of functions if the return type cannot be statically determined:

  function($x) as xs:integer+ { 1 to 1000000000, $x }(123)[1]

As the examples indicate, I would clearly be in favor of allowing iterative type checking.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115302</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2014-11-21 16:48:44 +0000</bug_when>
    <thetext>The errors and optimization section is far from perfect and will never be so unless we can find some new formalisms, but I think the optimizations you describe are clearly allowed (and widespread in current products, judging by the feedback we get on test cases). The rule is

the processor is free to stop examining further items in a sequence as soon as it can establish that further items would not affect the result except possibly by causing an error

and that is what you are doing.

The only exception to the above rule is the requirement to do cardinality checks. This is because it would have licensed the XPath 1.0 behavior of allowing things like contains(AUTHOR, &quot;Mike&quot;) where all but the first AUTHOR are ignored, and the XQuery WG had already decided it didn&apos;t like that feature of XPath 1.0.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>115354</commentid>
    <comment_count>2</comment_count>
    <who name="Christian Gruen">christian.gruen</who>
    <bug_when>2014-11-22 10:57:26 +0000</bug_when>
    <thetext>Thanks, Michael. I am marking this as resolved.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>