Subquery Optimization
You are looking at an older version of the documentation. The latest version is found here.
EXISTSsubqueries are typically rewritten toSELECT 1 FROM ...to prevent unnecessary evaluation ofSELECTexpressions;- Quantified compare 
SOMEsubqueries are always turned into an equivalentINpredicate or comparison against an aggregate value. e.g.col > SOME (SELECT col1 FROM table)would becomecol > (SELECT min(col1) FROM table); - Uncorrelated 
EXISTqueries and scalar subquery that are not pushed to the source can be pre-evaluated before source command formation; - Correlated subqueries used in 
DELETEorUPDATEqueries that are not pushed as part of the correspondingDELETE/UPDATEwill cause the Data Virtuality Server to perform row-by-row compensating processing. This will only happen if the affected table has a primary key. If it does not, an exception will be thrown; WHEREorHAVINGclauseIN, quantified comparison, scalar subquery compare, andEXISTpredicates can take theMJ(merge join),DJ(dependent join), orNO_UNNEST(no unnest) hints appearing just before the subquery. If possible, theMJhint directs the optimizer to use a traditional, semijoin, or anti-semi-join merge join. TheDJis the same as theMJhint, but additionally directs the optimizer to use the subquery as the independent side of a dependent join if possible. TheNO_UNNESThint, which supersedes the other hints, will direct the optimizer to leave the subquery in place.
Here are examples for each of them:
1. Merge join hint:SQLSELECT col1 FROM schm.tbl WHERE col2 IN /*+ MJ*/ (SELECT col1 FROM schm2.tbl2)2. Dependent join hint:
SQLSELECT col1 FROM schm.tbl WHERE col2 IN /*+ DJ */ (SELECT col1 FROM schm2.tbl2)2.
NO_UNNESThint:SQLSELECT col1 FROM schm.tbl WHERE col2 IN /*+ NO_UNNEST */ (SELECT col1 FROM schm2.tbl2)Be sure that there is no whitespace between
/*and+> when using e.g./*+ MJ */.Configure your SQL client not to remove multi-line comments.
Here is how to do this in Squirrel: Session -> Session Properties -> SQL -> Remove multi-line comment (/* ... */).- The system property 
org.teiid.subqueryUnnestDefaultcontrols whether the optimizer will, by default, unnest subqueries. The default is FALSE. IfTRUE, most non-negatedWHEREorHAVINGclause non-negatedEXISTSorINsubquery predicates can be converted to a traditional merge join or as antijoin or semijoin variants; WHEREclauseEXISTandINpredicates that can be rewritten to a traditional join with the semantics of the semijoin can be preserved if the system propertyorg.teiid.subqueryUnnestDefaultis set toTRUEor the subquery has anMJhint;- If the costing is favourable, the planner will always convert to antijoin or semijoin variants. Use a hint to override this behaviour if needed;
 EXISTand scalar subqueries that are not pushed down, and not converted to merge joins, are implicitly limited to 1 and 2 result rows, respectively;- Conversion of subquery predicates to nested loop joins is not yet available.