[MDEV-31361] Wrong result on 2nd execution of PS for query with derived table Created: 2023-05-29 Updated: 2024-02-06 Resolved: 2024-02-05 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Storage Engine - Federated |
| Affects Version/s: | 10.4, 10.5, 10.6, 10.9, 10.10, 11.0, 11.1 |
| Fix Version/s: | 11.3.2, 11.4.1, 10.5.25, 10.6.18, 10.11.8, 11.0.6, 11.1.5, 11.2.4 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Lena Startseva | Assignee: | Igor Babaev |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
Testcase:
Actual result:
Expected result:
|
| Comments |
| Comment by Oleg Smirnov [ 2023-12-11 ] | |||||||||||||||||||
|
igor, can you please review bb-10.4- | |||||||||||||||||||
| Comment by Oleg Smirnov [ 2023-12-14 ] | |||||||||||||||||||
|
igor's objections against the solution proposed at bb-10.4- I can agree with 1 and 2 but not with 3, for the following reasons: | |||||||||||||||||||
| Comment by Oleg Smirnov [ 2023-12-14 ] | |||||||||||||||||||
|
If I understood correctly, igor suggested implementing something like bb-10.4- | |||||||||||||||||||
| Comment by Oleg Smirnov [ 2023-12-27 ] | |||||||||||||||||||
|
As psergei complained about not having of an analysis provided, here's my version (igor can correct or complement).
Derived table dt3 is mergeable into dt2, but at the same time it is pushable, which implies it must be materialized (since an external engine is executing the SQL and fills the result table).
derived->change_refs_to_fields() effectively unsets the field translation previously made at TABLE_LIST::init_derived(), so the regular statement and first execution of the prepared statement completes successfully.
So, during second and further executions there is no call to derived->change_refs_to_fields(), and the field translation table (set at TABLE_LIST::init_derived()) remains effective. This leads to reading incorrect results from wrong fields. My solution proposed at bb-10.4- | |||||||||||||||||||
| Comment by Igor Babaev [ 2024-01-29 ] | |||||||||||||||||||
|
Assigned it to myself | |||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2024-02-04 ] | |||||||||||||||||||
|
OK to push a8217d7213a0d8c6faebfb50bdc839a53c7cf21b | |||||||||||||||||||
| Comment by Igor Babaev [ 2024-02-05 ] | |||||||||||||||||||
|
A fix for this bug was pushed into 10.5. It should be merged upstream as it is. |