@@ -586,9 +586,15 @@ def __deepcopy__(self, memodict={}) -> "SelectableEntity": # noqa: B006
586586 deepcopy (self .entity , memodict ), analyzer = self .analyzer
587587 )
588588 _deepcopy_selectable_fields (from_selectable = self , to_selectable = copied )
589- copied ._attributes = (
590- deepcopy (self ._attributes ) if self ._attributes is not None else None
591- )
589+ if (
590+ self ._session .reduce_describe_query_enabled
591+ and self ._session .cte_optimization_enabled
592+ ):
593+ copied ._attributes = (
594+ deepcopy (self ._attributes , memodict )
595+ if self ._attributes is not None
596+ else None
597+ )
592598 return copied
593599
594600 @property
@@ -929,9 +935,6 @@ def __copy__(self):
929935 )
930936 # The following values will change if they're None in the newly copied one so reset their values here
931937 # to avoid problems.
932- new ._attributes = (
933- self ._attributes .copy () if self ._attributes is not None else None
934- )
935938 new ._projection_in_str = None
936939 new ._schema_query = None
937940 new ._column_states = None
@@ -945,6 +948,13 @@ def __copy__(self):
945948 self ._merge_projection_complexity_with_subquery
946949 )
947950 new .df_ast_ids = self .df_ast_ids .copy () if self .df_ast_ids is not None else None
951+ if (
952+ self ._session .reduce_describe_query_enabled
953+ and self ._session .cte_optimization_enabled
954+ ):
955+ new ._attributes = (
956+ self ._attributes .copy () if self ._attributes is not None else None
957+ )
948958 return new
949959
950960 def __deepcopy__ (self , memodict = {}) -> "SelectStatement" : # noqa: B006
@@ -964,9 +974,15 @@ def __deepcopy__(self, memodict={}) -> "SelectStatement": # noqa: B006
964974 )
965975
966976 _deepcopy_selectable_fields (from_selectable = self , to_selectable = copied )
967- copied ._attributes = (
968- deepcopy (self ._attributes ) if self ._attributes is not None else None
969- )
977+ if (
978+ self ._session .reduce_describe_query_enabled
979+ and self ._session .cte_optimization_enabled
980+ ):
981+ copied ._attributes = (
982+ deepcopy (self ._attributes , memodict )
983+ if self ._attributes is not None
984+ else None
985+ )
970986 copied ._projection_in_str = self ._projection_in_str
971987 copied ._query_params = deepcopy (self ._query_params )
972988 copied ._merge_projection_complexity_with_subquery = (
@@ -1412,7 +1428,11 @@ def select(self, cols: List[Expression]) -> "SelectStatement":
14121428 if can_be_flattened :
14131429 new = copy (self )
14141430 final_projection = []
1415- new ._attributes = None # reset attributes since projection changed
1431+ if (
1432+ self ._session .reduce_describe_query_enabled
1433+ and self ._session .cte_optimization_enabled
1434+ ):
1435+ new ._attributes = None # reset attributes since projection changed
14161436 assert new_column_states is not None
14171437 for col , state in new_column_states .items ():
14181438 if state .change_state in (
0 commit comments