Details
-
Bug
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.4.31
Description
CREATE TABLE aggregates |
(
|
`date` date, |
`ticker` varchar(3), |
l float, |
is_fs tinyint(1)
|
);
|
|
INSERT INTO aggregates |
VALUES
|
('2016-08-02', 'GFF', 16.75, NULL), |
('2016-08-24', 'GFF', 16.75, NULL), |
('2016-09-16', 'GFF', 16.75, NULL), |
('2016-01-06', 'GFF', 16.75, NULL), |
('2016-10-10', 'GFF', 16.75, NULL); |
|
SELECT
|
|
(1=1)
|
AND
|
(
|
(LAG(l) OVER (PARTITION BY ticker ORDER BY date) > 1 AND 1=1)
|
OR (LAG(l) OVER (PARTITION BY ticker ORDER BY date) > 1 AND 1=1)
|
)
|
|
AS is_fs FROM `aggregates` WHERE YEAR(date) = 2016 AND ticker = 'GFF' ORDER BY is_fs DESC
|
result:
NULL
|
NULL
|
NULL
|
NULL
|
NULL
|
https://www.db-fiddle.com/f/iEoGYnnKA3pmkB9piu8pWk/0
MySQL-8.0 result |
1
|
1
|
1
|
1
|
NULL
|
|
Attachments
Issue Links
- links to
The problem is caused by the 3-level Window Function dependency tree.
Simplified query:
-- Setup
(
is_fs tinyint(1)
);
VALUES
-- Problematic Query
SELECT
(
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.