title: DB2 pureXML index usage in ORDER BY clause
body: <p>I got a problem with the index usage in DB2 XML. I have a database table with users, consisting of id + xml document + timestamp. The thing i'm interested in is to find users and order them by join date. </p>
  
  <p>The index definition:</p>
  
  <pre><code>create index idx_joindate on "Users"("userXML") generate keys 
      using xmlpattern '/*:User/*:joinDate' as sql timestamp;
  </code></pre>
  
  <p>The SQL query:</p>
  
  <pre><code>SELECT "Users".* FROM "Users" 
    ORDER BY 
     XMLCAST(
      XMLQUERY('$i/*:User/*:joinDate' PASSING "userXML" AS "i") 
     as TIMESTAMP) DESC
  FETCH FIRST 20 ROWS ONLY
  </code></pre>
  
  <p>The XQuery:</p>
  
  <pre><code>xquery
  let $sorted :=
     for $user in db2-fn:xmlcolumn("Users.userXML")
     order by xs:dateTime($user/*:User/*:joinDate) descending
     return $user
  for $user in subsequence($sorted, 1, 20)
  return $user
  </code></pre>
  
  <p>Both queries actually work fine, BUT I expect them to use the defined index on the joinDate. This does not happen for neither XQuery nor SQL query.</p>