Affects Version/s: None
Fix Version/s: None
Currently, there are some merge rules for project, such as CalcMergeRule, ProjectMergeRule, and ProjectCalcMergeRule. I found that these merge rules should not be performed when Nondeterministic expression of the bottom project has been referenced more than once by the top project. Take the following test as an example:
The first select generates `a` from `rand()` and the second select generate `a1` and `a2` from `a`. From the SQL, `a1` should equal to `a2`.
Let's take a look at the result plan:
In the plan, a1 may not equal to a2 due to the projects merge which is against the SQL(a1 equals to a2).
One option to solve the problem is to disable these merge rules in such cases, so that the result plan will be:
Any suggestions are greatly appreciated.