Bug #101691 | Use substring_index and rank() in a sql cause wrong result | ||
---|---|---|---|
Submitted: | 20 Nov 2020 7:25 | Modified: | 20 Nov 2020 7:45 |
Reporter: | Baolin Huang | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
Version: | 8.0.22, 8.0.17, 8.0.18 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | regression |
[20 Nov 2020 7:25]
Baolin Huang
[20 Nov 2020 7:45]
MySQL Verification Team
Hello Baolin Huang, Thank you for the report and feedback. regards, Umesh
[5 Nov 2021 13:48]
Steinar Gunderson
Posted by developer: Fixed by commit ba373ed2e3b5d9b0465e1d1e6240db84c2e237fe Author: Dag Wanvik <dag.wanvik@oracle.com> Date: Tue Sep 28 13:21:53 2021 +0200 Bug#33399696 window function returns wrong result This is a regression introduced in 8.0.17 (by 88539ef3e67, part of WL#12788: Iterator executor for window functions). In the WindowIterator::Read() function, resetting of active slice is not done when we reach the end of the input result set for windowing. This causes reading wrong values when we reach the sorting of ORDER BY: active slice is still set to slice 1 which points to the items being read from the input table, whereas the ORDER BY sorting stage needs to read the values after computation of the window function(s). For this, it needs the active slice to be that of the last window's output table, slice 4 in this case. Fix: move the resetting of the slice to the output slice immediately after read, so that it is set correctly also when we return due to no more rows seen in the input set and move on to the ordering. Patch contributed by casazhang@tencent.com Change-Id: I7393075ebdbb37fb1966eeff72223caf38316457