Currently sub-query correlated variables have a brittle contract with their containing RelNode. Simple rules such as ones that transpose filters and projects are unaware of this contract and would be difficult to retrofit to handle all the rules to be sub-query aware.
A correlated sub-query is logically a function call with where its parameters are the values used for the correlated inputs. If the SubQuery object was structured such that the inputs that are used as correlated variables were explicit sub nodes of the sub-query object, then most rules and utilities, such as the trimmer, would just work as expected. SqlToRel could also be simplified since there would only be one place to add the CorrelationId oppose to 3. James
