skip to main content
Implementing Table Expression Pushdown : About Table Expression Pushdown : Handling Correlated Queries
 

Handling Correlated Queries

When correlated queries are used, the correlated subquery is executed for each record of the outer table. When the IP executes the correlated subquery, it needs to detect that the condition refers to a correlated column (column of parent query) and use the value of the column in the search expression it builds.
Example:
SELECT deptno, ename, sal FROM emp x WHERE sal > 1000 AND deptno =(SELECT deptno FROM dept WHERE deptno = x.deptno);
To detect a correlated column, the IP should call damex_isCorrelatedCol() to determine whether a column is of the current query or parent query. When the IP queries dept, the x.deptno column is a correlated column. If damex_isCorrelatedCol() returns TRUE, the IP should use dam_getJoinColValue() to get the value of this column. See Pseudo-code for Getting the Table Expression for more information.