Selecting Data

To minimize data retrieval, DataDirect XQuery generates very selective SQL, returning only the data that is needed for a given XQuery. To avoid retrieving rows that are not needed, the conditions in Where clauses and predicates are converted to Where clauses in the generated SQL. To avoid retrieving columns that are not needed, the generated SQL specifies the columns actually needed to evaluate the XQuery. Some XQuery implementations retrieve much more data than is actually needed, which significantly hurts performance.

Example 1. Where Clause Pushdown

In this example, the SQL query generated by DataDirect XQuery returns only the rows that are actually needed for the XQuery.

XQuery (with Where clause)

for $h in collection('HOLDINGS')/HOLDINGS
where $h/SHARES < 10000
return $h/USERID

XQuery (with predicate)

for $h in collection('HOLDINGS')/HOLDINGS[SHARES < 10000]
return $h/USERID

Generated SQL (for both forms of the XQuery)

SELECT ALL
nrm4."USERID" AS RACOL1
FROM
"PEPPINO"."HOLDINGS" nrm4
WHERE
nrm4."SHARES" < 10000

Example 2. Column Pushdown

The SQL query generated by DataDirect XQuery retrieves only the columns that are actually needed for the XQuery.

XQuery

for $u in collection('USERS')/USERS
return <user>{$u/FIRSTNAME,$u/LASTNAME}</user>

Generated SQL

SELECT ALL
nrm5."FIRSTNAME" AS RACOL1,
nrm5."LASTNAME" AS RACOL2
FROM
"PEPPINO"."USERS" nrm5
Previous

DataDirect XQuery™ Performance: Generating SQL
HomeNext

Quantifiers