[MDEV-30828] ORDER BY clause using an integer (positional argument) on a SELECT query involving a pushed down UNION produces incorrect results Created: 2023-03-10 Updated: 2023-11-23 Resolved: 2023-06-30 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Server |
| Affects Version/s: | 10.6.12 |
| Fix Version/s: | 11.1.2, 11.2.1 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Gagan Goel (Inactive) | Assignee: | Oleg Smirnov |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||||||
| Description |
|
The below diff shows incorrect outputs on the federatedx storage engine:
The expected output for the above 3 queries should be as follows (here i1 and i2 are equivalent InnoDB tables):
It is possible query 3 is currently not supported by the federatedx storage engine. But for queries 1 and 2, the server should error out (as is the case with InnoDB) before attempting to pushdown the query to the foreign engine. |
| Comments |
| Comment by Oleg Smirnov [ 2023-03-23 ] | ||||
|
>> Server execution not reaching find_order_in_list() in sql/sql_select.cc is the problem/bug here find_order_in_list() is called for a JOIN corresponding to the execution of fake_select_lex mentioned above. When fake_select_lex isn't employed there's no call to find_order_in_list(). | ||||
| Comment by Oleg Smirnov [ 2023-04-03 ] | ||||
|
tntnatbry, I've pushed 10.6-mdev-30828 to the ES which addresses the first issue: pushing down SQL with incorrect ORDER BY. Now such statements will error out on the MariaDB side. There is another issue with FederatedX producing unordered results which I'm planning to fix next. Regarding the bad side effect: statements
and
are different in terms of column "a" meaning. The "order by a" clause in the case of union relates to the result of the union and not to the particular table column. So the statement can be represented as
There can even be a statement like this:
It's not possible to have an Item* referring to "t1.a" since there's no such column in t1. "a" in the ORDER BY must probably refer to a temporary table containing results of the UNION. | ||||
| Comment by Oleg Smirnov [ 2023-04-12 ] | ||||
|
It turned out to be not so easy to implement global ORDER BY (i.e. related to the whole UNION/EXCEPT/INTERSECT) validation before the pushdown. The problem is we select and initialize the pushdown handler in st_select_unit::prepare(). The structure responsible for global ORDER BY is fake_select_lex. But fake_select_lex is not validated completely at prepare(), some validation steps are performed later, during the execution phase at st_select_unit::exec_inner(), when calling mysql_select(). I haven't succeded with trying to add the complete fake_select_lex validation to st_select_unit::prepare(). A lot of test cases start failing in different places of code since it's an architectural change. My suggestion is to restrict pushing down units having global ORDER BY and/or GROUP BY. | ||||
| Comment by Oleg Smirnov [ 2023-05-08 ] | ||||
|
The fix is pushed to ES 10.6-mdev-30828. | ||||
| Comment by Oleksandr Byelkin [ 2023-06-26 ] | ||||
|
OK to push |