[MDEV-32349] Window Lag function returning different result under from MySQL-8.0 Created: 2023-10-04 Updated: 2023-10-31 |
|
| Status: | Open |
| Project: | MariaDB Server |
| Component/s: | Optimizer - Window functions |
| Affects Version/s: | 10.4.31 |
| Fix Version/s: | 10.4, 10.6 |
| Type: | Bug | Priority: | Major |
| Reporter: | Daniel Black | Assignee: | Vicențiu Ciorbaru |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Description |
|
result:
https://www.db-fiddle.com/f/iEoGYnnKA3pmkB9piu8pWk/0
|
| Comments |
| Comment by Vicențiu Ciorbaru [ 2023-10-09 ] | |||||||||||||||||||||
|
The problem is caused by the 3-level Window Function dependency tree. Simplified query:
The execution of this query generates a temporary table with the following fields corresponding to the following Item subtrees (in this order)
The problem with this field order is that the final step in window function computation does not consider field dependencies properly. To be able to fill the whole table, one must start by computing window functions first (which is done correctly), then the items depending directly on window functions, then the items depending indirectly and so on. We currently only properly handle first and second level items containing window functions. 3 levels and more are not evaluated in proper order, hence this bug. This translates into a need to do a topological sort of temp-table fields before saving the actual results. | |||||||||||||||||||||
| Comment by Vicențiu Ciorbaru [ 2023-10-09 ] | |||||||||||||||||||||
|
Discussion with psergei: Items can be split into 3 categories: With this in mind, there should be no need for topological sorting, as all items of type 3 can be computed regardless of ordering. The current code however creates separate columns in the tmp table depending on the expression tree with type 3 items referencing window functions directly, but also with type 3 items referencing window functions via one item indirection. This needs to be investigated further to see why we have an extra layer of Item_refs placed in the tmp table. |