From ec7695632aed7c279416ec061c88899e5c94d04e Mon Sep 17 00:00:00 2001 From: hopelee Date: Sun, 21 Mar 2021 17:22:34 +0800 Subject: [PATCH] Bugfix Window with buffering follows JT_EQ_REF returns wrong NULL result Description ----------- After the window function calculation in a partition has completed, multiple rows are ready for output. And the server is going to output the first row in the partition. But the server will read the row again from the input table because Window::needs_restore_input_row() returns true, this will override the NULL bit flags which have already been set to the correct value in process_buffered_windowing_record()->copy_funcs(). So the server returns wrong NULL values. Fix --- When there are multiple rows ready for output, don't read the record again. --- sql/composite_iterators.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sql/composite_iterators.cc b/sql/composite_iterators.cc index 8a1af4a8a46..33a0574ec95 100644 --- a/sql/composite_iterators.cc +++ b/sql/composite_iterators.cc @@ -1545,7 +1545,11 @@ int BufferingWindowingIterator::Read() { return 1; } - if (m_window->needs_restore_input_row()) { + /* + If there are multiple rows ready for output, we don't need to read the + record again. This will override the NULL flags in results. + */ + if (!m_possibly_buffered_rows && m_window->needs_restore_input_row()) { /* Reestablish last row read from input table in case it is needed again before reading a new row. May be necessary if this is the -- 2.19.1.6.gb485710b