What is TargetListManager?
It manages all expressions used in a query block, and their reference names. TargetListManager provides a way to find an expression by a reference name. It keeps a set of expressions, and one or more reference names can point to the same expression. Also, TargetListManager keeps the evaluation state of each expression. The evaluation state is a boolean state to indicate whether the expression was evaluated in descendant node or not. If an expression is evaluated, the evaluation state is changed to TRUE. It also means that the expression can be referred by an column reference instead of evaluating the expression. Consider an example query: SELECT sum(l_orderkey + 1) from lineitem where l_partkey > 1; In this case, an expression sum(l_orderkey + 1) is divided into two sub expressions:
- $1 <- l_orderkey + 1
- $2 <- sum($1)
$1
is a simple arithmetic operation, and $2 is an aggregation function.
$1
is evaluated in ScanNode because it's just a simple arithmetic operation. So, the evaluation state of l_orderkey + 1 initially is false, but the state will be true after ScanNode. In contrast, sum($1) is evaluated at GroupbyNode. So, its evaluation state is changed after GroupByNode.
Why is TargetListManager necessary?
Expressions used in a query block can be divided into various categories according to the possible {@link Projectable} nodes. Their references become available depending onthe Projectable node at which expressions are evaluated. It manages the expressions and references for optimized places of expressions. It performs duplicated removal and enables common expressions to be shared with two or more Projectable nodes. It also helps Projectable nodes to find correct column references.