Another way DataDirect XQuery minimizes data retrieval is by implementing quantified expressions with SQL in the database. These expressions are generally used in predicates and Where clauses, reducing the number of rows retrieved from the database.
Example 3. Quantifier Pushdown
XQuery
for $u in collection("USERS")/USERS
where every $h in collection("HOLDINGS")/HOLDINGS[USERID=$u/USERID]
satisfies $h/SHARES > 1000
return <user id="{$u/LASTNAME}"/>
Generated SQL
SELECT ALL
nrm5."LASTNAME" AS RACOL2
FROM
"PEPPINO"."USERS" nrm5
WHERE
NOT EXISTS(
SELECT ALL 1 AS RACOL1
FROM "PEPPINO"."HOLDINGS" nrm10
WHERE CASE WHEN nrm10."SHARES" > 1000 THEN 0 ELSE 1 END) !=0
AND nrm10."USERID" = nrm5."USERID"
AND LENGTH(nrm10."USERID") = LENGTH(nrm5."USERID")
)
| Previous Selecting Data | Home | Next Joins |