@@ -61,22 +61,24 @@ impl ExprVisitorMut<'_> for WindowCollector<'_, '_> {
6161 }
6262}
6363
64- struct WindowOutputBinder {
65- outputs : Vec < ( ColumnRef , usize ) > ,
64+ struct WindowOutputBinder < ' a > {
65+ groups : & ' a [ WindowGroup ] ,
66+ base_position : usize ,
6667}
6768
68- impl ExprVisitorMut < ' _ > for WindowOutputBinder {
69+ impl ExprVisitorMut < ' _ > for WindowOutputBinder < ' _ > {
6970 fn visit_column_ref (
7071 & mut self ,
7172 column : & mut ColumnRef ,
7273 position : & mut usize ,
7374 ) -> Result < ( ) , DatabaseError > {
74- if let Some ( ( _ , output_position) ) = self
75- . outputs
75+ if let Some ( output_position) = self
76+ . groups
7677 . iter ( )
77- . find ( |( output_column, _) | output_column == column)
78+ . flat_map ( |group| & group. output_columns )
79+ . position ( |output_column| output_column == column)
7880 {
79- * position = * output_position;
81+ * position = self . base_position + output_position;
8082 }
8183 Ok ( ( ) )
8284 }
@@ -203,24 +205,16 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
203205 }
204206 }
205207
206- let mut outputs = Vec :: new ( ) ;
207- let mut position = base_position;
208- for group in & groups {
209- for column in & group. output_columns {
210- outputs. push ( ( * column, position) ) ;
211- position += 1 ;
212- }
213- }
214-
215- let mut output_binder = WindowOutputBinder { outputs } ;
216- for expr in select_list {
208+ let mut output_binder = WindowOutputBinder {
209+ groups : & groups,
210+ base_position,
211+ } ;
212+ for expr in select_list
213+ . iter_mut ( )
214+ . chain ( order_by. iter_mut ( ) . flatten ( ) . map ( |field| & mut field. expr ) )
215+ {
217216 output_binder. visit ( expr) ?;
218217 }
219- if let Some ( order_by) = order_by {
220- for field in order_by {
221- output_binder. visit ( & mut field. expr ) ?;
222- }
223- }
224218
225219 for group in groups {
226220 let sort_fields = group
0 commit comments