Make our SelectExpression cloning mechanism compatible with external roots #30982
Labels
area-query
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
type-bug
Milestone
We have a CloningExpressionVisitor which is used to deep-clone a SelectExpression; it knows about some specific expression types (SelectExpression, TpcTablesExpression, TableValuedFunctionExpression), and also recognizes IClonableTableExpressionBase, which table expressions can implement in order to have their own cloning logic.
However, since IClonableTableExpressionBase.Clone() doesn't accept the cloning visitor itself, it's impossible for such custom cloning implementations to recurse into their contained sub-expressions. For example, ValuesExpression performs a shallow copy of itself, meaning that the copy references the same elements as the original. Also, SqlServerOpenJsonExpression gets cloned as a TableValuedExpression (which it extends), but the extra data it adds doesn't get cloned; it could implement IClonableTableExpressionBase, but would then again have to implement shallow copying.
We can pass the cloning visitor as a parameter to Clone, so that implementations can deep-copy.
The text was updated successfully, but these errors were encountered: