@@ -92,14 +92,20 @@ impl<'a, T: Transaction> Binder<'a, T> {
9292 expr : & mut ScalarExpression ,
9393 is_select : bool ,
9494 ) -> Result < ( ) , BindError > {
95+ let ref_columns = expr. referenced_columns ( ) ;
96+
9597 match expr {
9698 ScalarExpression :: AggCall {
9799 ty : return_type, ..
98100 } => {
99101 let ty = return_type. clone ( ) ;
100102 if is_select {
101103 let index = self . context . input_ref_index ( InputRefType :: AggCall ) ;
102- let input_ref = ScalarExpression :: InputRef { index, ty } ;
104+ let input_ref = ScalarExpression :: InputRef {
105+ index,
106+ ty,
107+ ref_columns,
108+ } ;
103109 match std:: mem:: replace ( expr, input_ref) {
104110 ScalarExpression :: AggCall {
105111 kind,
@@ -124,14 +130,21 @@ impl<'a, T: Transaction> Binder<'a, T> {
124130 . find_position ( |agg_expr| agg_expr == & expr)
125131 . ok_or_else ( || BindError :: AggMiss ( format ! ( "{:?}" , expr) ) ) ?;
126132
127- let _ = std:: mem:: replace ( expr, ScalarExpression :: InputRef { index, ty } ) ;
133+ let _ = std:: mem:: replace (
134+ expr,
135+ ScalarExpression :: InputRef {
136+ index,
137+ ty,
138+ ref_columns,
139+ } ,
140+ ) ;
128141 }
129142 }
130143
131144 ScalarExpression :: TypeCast { expr, .. } => {
132145 self . visit_column_agg_expr ( expr, is_select) ?
133146 }
134- ScalarExpression :: IsNull { expr } => self . visit_column_agg_expr ( expr, is_select) ?,
147+ ScalarExpression :: IsNull { expr, .. } => self . visit_column_agg_expr ( expr, is_select) ?,
135148 ScalarExpression :: Unary { expr, .. } => self . visit_column_agg_expr ( expr, is_select) ?,
136149 ScalarExpression :: Alias { expr, .. } => self . visit_column_agg_expr ( expr, is_select) ?,
137150 ScalarExpression :: Binary {
@@ -228,13 +241,15 @@ impl<'a, T: Transaction> Binder<'a, T> {
228241 } ) {
229242 let index = self . context . input_ref_index ( InputRefType :: GroupBy ) ;
230243 let mut select_item = & mut select_list[ i] ;
244+ let ref_columns = select_item. referenced_columns ( ) ;
231245 let return_type = select_item. return_type ( ) ;
232246
233247 self . context . group_by_exprs . push ( std:: mem:: replace (
234248 & mut select_item,
235249 ScalarExpression :: InputRef {
236250 index,
237251 ty : return_type,
252+ ref_columns,
238253 } ,
239254 ) ) ;
240255 return ;
@@ -243,6 +258,8 @@ impl<'a, T: Transaction> Binder<'a, T> {
243258
244259 if let Some ( i) = select_list. iter ( ) . position ( |column| column == expr) {
245260 let expr = & mut select_list[ i] ;
261+ let ref_columns = expr. referenced_columns ( ) ;
262+
246263 match expr {
247264 ScalarExpression :: Constant ( _) | ScalarExpression :: ColumnRef { .. } => {
248265 self . context . group_by_exprs . push ( expr. clone ( ) )
@@ -255,6 +272,7 @@ impl<'a, T: Transaction> Binder<'a, T> {
255272 ScalarExpression :: InputRef {
256273 index,
257274 ty : expr. return_type ( ) ,
275+ ref_columns,
258276 } ,
259277 ) )
260278 }
@@ -300,7 +318,7 @@ impl<'a, T: Transaction> Binder<'a, T> {
300318 }
301319
302320 ScalarExpression :: TypeCast { expr, .. } => self . validate_having_orderby ( expr) ,
303- ScalarExpression :: IsNull { expr } => self . validate_having_orderby ( expr) ,
321+ ScalarExpression :: IsNull { expr, .. } => self . validate_having_orderby ( expr) ,
304322 ScalarExpression :: Unary { expr, .. } => self . validate_having_orderby ( expr) ,
305323 ScalarExpression :: Binary {
306324 left_expr,
0 commit comments