Consistent SQL Generation

In XQuery, many queries may be semantically equivalent. DataDirect XQuery recognizes common equivalences in queries and ensures that efficient SQL is generated for all the different ways of expressing a query.

Example 17. SQL Generation for Equivalent Queries

XQuery (all of these queries are equivalent)

collection("USERS")/USERS/FIRSTNAME[.='John']

collection("USERS")//FIRSTNAME[.='John']

collection("USERS")/USERS[FIRSTNAME='John']/FIRSTNAME

for $u in collection("USERS")/USERS
where $u/FIRSTNAME = 'John'
return $u/FIRSTNAME

declare function local:testUser($firstname) {$firstname = 'John'};
for $u in collection("USERS")/USERS
where local:testUser ($u/FIRSTNAME)
return $u/FIRSTNAME

for $u in collection("USERS")/USERS
return if ($u/FIRSTNAME = 'John') then $u/FIRSTNAME else ()

Generated SQL (generated for all the above queries)

SELECT ALL
nrm6."FIRSTNAME" AS RACOL1
FROM
"PEPPINO"."USERS" nrm6
WHERE
nrm6."FIRSTNAME" = 'John' AND
LENGTH(nrm6."FIRSTNAME") = LENGTH('John')
Previous

Calling Database Functions
HomeNext

Relaxing XQuery Semantics

Copyright © 1993 - 2008. Progress Software Corporation. All rights reserved. | N. America: 800 876 3101 | World: +44 (0) 1753 218 930