Example optimization profiles contain general request, access method, and join order guidelines to control how optimization is performed on queries that access XML data.
For information about optimization guidelines and using optimization profiles, see the related links at the end of this topic.
<?xml version="1.0" encoding="UTF-8"?>
<OPTPROFILE VERSION="9.7.0.0">
<STMTPROFILE ID="Security Tables">
<STMTKEY SCHEMA="ST">
SELECT *
FROM security
WHERE XMLEXISTS('$SDOC/Security/SecurityInfo
/StockInfo[Industry= "OfficeSupplies"]')
</STMTKEY>
<OPTGUIDELINES>
<DPFXMLMOVEMENT VALUE="REFERENCE"/>
</OPTGUIDELINES>
</STMTPROFILE>
</OPTPROFILE>
<?xml version="1.0" encoding="UTF-8"?>
<OPTPROFILE VERSION="9.7.0.0">
<STMTPROFILE ID="Security Tables">
<STMTKEY SCHEMA="ST">
SELECT *
FROM security
WHERE XMLEXISTS('$SDOC/Security/SecurityInfo
/StockInfo[Industry= "OfficeSupplies"]')
</STMTKEY>
<OPTGUIDELINES>
<XISCAN TABLE='SECURITY' INDEX='SEC_INDUSTRY'/>
</OPTGUIDELINES>
</STMTPROFILE>
</OPTPROFILE>
<?xml version="1.0" encoding="UTF-8"?>
<OPTPROFILE VERSION="9.7.0.0">
<STMTPROFILE ID="Security Tables by Date">
<STMTKEY SCHEMA="STBD">
SELECT *
FROM security
WHERE trans_date = CURRENT DATE
AND XMLEXISTS('$SDOC/Security/SecurityInfo
/StockInfo[Industry= "Software"]')
AND XMLEXISTS('$SDOC/Security/Symbol[.="IBM"]')
</STMTKEY>
<OPTGUIDELINES>
<XANDOR TABLE='SECURITY' />
</OPTGUIDELINES>
</STMTPROFILE>
</OPTPROFILE>
<?xml version="1.0" encoding="UTF-8"?>
<OPTPROFILE VERSION="9.7.0.0">
<STMTPROFILE ID="Security Tables by Date">
<STMTKEY SCHEMA="STBD">
SELECT *
FROM security
WHERE trans_date = CURRENT DATE
AND XMLEXISTS('$SDOC/Security/SecurityInfo
/StockInfo[Industry= "Software"]')
AND XMLEXISTS('$SDOC/Security/Symbol[.="IBM"]')
</STMTKEY>
<OPTGUIDELINES>
<IXAND TABLE='SECURITY' TYPE='XMLINDEX'>
<INDEX IXNAME='SEC_INDUSTRY'/>
<INDEX IXNAME='SEC_SYMBOL'/>
</IXAND>
</OPTGUIDELINES>
</STMTPROFILE>
</OPTPROFILE>
<?xml version="1.0" encoding="UTF-8"?>
<OPTPROFILE VERSION="9.7.0.0">
<STMTPROFILE ID="Security Tables by Date">
<STMTKEY SCHEMA="STBD">
SELECT *
FROM security
WHERE trans_date = CURRENT DATE
AND XMLEXISTS('$SDOC/Security/SecurityInfo
/StockInfo[Industry= "Software"]')
AND XMLEXISTS('$SDOC/Security/Symbol[.="IBM"]')
</STMTKEY>
<OPTGUIDELINES>
<IXAND TABLE='SECURITY' TYPE='XMLINDEX' ALLINDEXES='TRUE' />
</OPTGUIDELINES>
</STMTPROFILE>
</OPTPROFILE>
<?xml version="1.0" encoding="UTF-8"?>
<OPTPROFILE VERSION="9.7.0.0">
<STMTPROFILE ID="Security Tables by Date">
<STMTKEY SCHEMA="STBD">
SELECT *
FROM security
WHERE trans_date = CURRENT DATE
AND XMLEXISTS('$SDOC/Security/SecurityInfo
/StockInfo[Industry= "Software"]')
AND XMLEXISTS('$SDOC/Security/Symbol[.="IBM"]')
</STMTKEY>
<OPTGUIDELINES>
<IXAND TABLE='SECURITY' TYPE='XMLINDEX' INDEX='SEC_INDUSTRY' />
</OPTGUIDELINES>
</STMTPROFILE>
</OPTPROFILE>
<?xml version="1.0" encoding="UTF-8"?>
<OPTPROFILE VERSION="9.7.0.0">
<STMTPROFILE ID="Security Tables">
<STMTKEY SCHEMA="ST">
SELECT *
FROM security
WHERE XMLEXISTS('$SDOC/Security/SecurityInfo
/StockInfo[Industry= "OfficeSupplies"]')
</STMTKEY>
<OPTGUIDELINES>
<ACCESS TABLE='SECURITY' TYPE='XMLINDEX' />
</OPTGUIDELINES>
</STMTPROFILE>
</OPTPROFILE>
<?xml version="1.0" encoding="UTF-8"?>
<OPTPROFILE VERSION="9.7.0.0">
<STMTPROFILE ID="Security Tables 2">
<STMTKEY SCHEMA="ST2">
SELECT *
FROM security
WHERE XMLEXISTS('$SDOC/Security/SecurityInfo
/StockInfo[Industry= "Software"]')
AND XMLEXISTS('$SDOC/Security/Symbol[.="IBM"]')
</STMTKEY>
<OPTGUIDELINES>
<ACCESS TABLE='SECURITY' TYPE='XMLINDEX' ALLINDEXES='TRUE' />
</OPTGUIDELINES>
</STMTPROFILE>
</OPTPROFILE>
<?xml version="1.0" encoding="UTF-8"?>
<OPTPROFILE VERSION="9.7.0.0">
<STMTPROFILE ID="Security Tables by Date">
<STMTKEY SCHEMA="STBD">
SELECT *
FROM security
WHERE trans_date = CURRENT DATE
AND XMLEXISTS('$SDOC/Security/SecurityInfo
/StockInfo[Industry= "Software"]')
AND XMLEXISTS('$SDOC/Security/Symbol[.="IBM"]')
</STMTKEY>
<OPTGUIDELINES>
<ACCESS TABLE='SECURITY' TYPE='XMLINDEX' INDEX='SEC_INDUSTRY' />
</OPTGUIDELINES>
</STMTPROFILE>
</OPTPROFILE>
<OPTGUIDELINES>
<ACCESS TABLE='SECURITY' TYPE='XMLINDEX'>
<INDEX IXNAME='SEC_INDUSTRY'/>
<INDEX IXNAME='SEC_SYMBOL'/>
</ACCESS>
</OPTGUIDELINES>
<?xml version="1.0" encoding="UTF-8"?>
<OPTPROFILE VERSION="9.7.0.0">
<STMTPROFILE ID="Order and Security Tables">
<STMTKEY SCHEMA="OST">
SELECT ordqty, orddate, ordid, security, lasttrade
FROM order, security, custacc,
XMLTABLE('$ODOC/FIXML/Order'
COLUMNS ordid VARCHAR(10) PATH '@ID',
orddate date PATH '@TrdDt',
ordqty float PATH 'OrdQty/@Qty') AS T1,
XMLTABLE(' $SDOC/Security'
COLUMNS security varchar(50) PATH 'Name',
lasttrade float PATH 'Price/LastTrade') AS T2
WHERE XMLEXISTS('
$SDOC/Security[Symbol/fn:string(.)
= $ODOC/FIXML/Order/Instrmt/@Sym/fn:string(.)]')
and XMLEXISTS(
'$ODOC/FIXML/Order[@Acct/fn:string(.)
= $CADOC/Customer/Accounts/Account/@id/fn:string(.)]')
and XMLEXISTS('$CADOC/Customer[@id = 1011]')
ORDER BY ordqty desc
</STMTKEY>
<OPTGUIDELINES>
<ACCESS TABLE='CUSTACC' TYPE='XMLINDEX' FIRST='TRUE' />
<XANDOR TABLE='ORDER' />
</OPTGUIDELINES>
</STMTPROFILE>
</OPTPROFILE>
<?xml version="1.0" encoding="UTF-8"?>
<OPTPROFILE VERSION="9.7.0.0">
<STMTPROFILE ID="Security Tables by Industry">
<STMTKEY SCHEMA="STBD">
xquery
for $sinfo1 in db2-fn:xmlcolumn("SECURITY1.SDOC")/Security/SecurityInfo
/StockInfo[Industry="Software"]
return $sinfo1
</STMTKEY>
<OPTGUIDELINES>
<XISCAN TABLE='SECURITY1' INDEX='XI1'/>
</OPTGUIDELINES>
</STMTPROFILE>
</OPTPROFILE>
The following optimization profile contains an XQuery expression that returns stock information of a company that deals in Software as well as Electronics.
<?xml version="1.0" encoding="UTF-8"?>
<OPTPROFILE VERSION="9.7.0.0">
<STMTPROFILE ID="Security Tables by Industry">
<STMTKEY SCHEMA="STBD">
<![CDATA[ xquery
for $sinfo1 in db2-fn:xmlcolumn("SECURITY1.SDOC")/Security
/SecurityInfo/StockInfo[Industry="Software"]
for $sinfo2 in db2-fn:xmlcolumn("SECURITY2.SDOC")/Security
/SecurityInfo/StockInfo[Industry="Electronics"]
where $sinfo1 = $sinfo2
return <stock> {$sinfo1} </stock> ]]>
</STMTKEY>
<OPTGUIDELINES>
<JOIN>
<ACCESS TABLE='SECURITY2' TYPE='XMLINDEX' INDEX='XI2'/>
<ACCESS TABLE='SECURITY1' TYPE='XMLINDEX' INDEX='XI1'/>
</JOIN>
</OPTGUIDELINES>
</STMTPROFILE>
</OPTPROFILE>
A CDATA section starting, with <![CDATA[ and ending
with ]]>, encloses the statement key in the STMTKEY element because
the statement key contains the special XML characters < and >.
The profile parser ignores the XML tags in the CDATA section, but
the optimizer still uses the entire statement key to match a statement
profile to a corresponding statement in an application.