[MDEV-27172] Prefix indices on Spider tables may lead to wrong query results Created: 2021-12-06 Updated: 2023-11-27 Resolved: 2022-09-01 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer, Storage Engine - Spider |
| Affects Version/s: | 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8 |
| Fix Version/s: | 10.3.37, 10.4.27, 10.5.18, 10.6.10, 10.7.6, 10.8.5, 10.9.3, 10.10.2 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Daniel YE | Assignee: | Nayuta Yanagisawa (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
| Comments |
| Comment by Nayuta Yanagisawa (Inactive) [ 2021-12-06 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
DanielYe133 Thank you for your report. In which version have you found the above behavior? Possibly, you've tested on TSpider based on MariaDB 10.3? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Daniel YE [ 2021-12-06 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
nayuta-yanagisawa It was initially found on TSpider based on MariaDB 10.3.7. Then I reproduced it on MariaDB 10.6.4. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2021-12-06 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
DanielYe133 Thank you. I will check it soon. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2022-01-12 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Roel Could you please verify the bug? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Roel Van de Paar [ 2022-01-14 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Partially verified on 10.8 as described. Tested 10.4 to 10.8, same result. Likely also present in earlier versions.
Leads to:
Besides the issue reported, why is there double output? This looks like a serious bug, as a similar but simpler testcase does not produce such double output:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Roel Van de Paar [ 2022-01-14 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
For completeness, InnoDB seems to work correctly for the same testcase:
Leads to:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2022-02-16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This is possibly because of MRR, which is disabled in TSpider, but I will look at it further. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2022-02-24 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Roel This was not true. You associated the single remote table with different partitions of the Spider table. This will surely double the result set from a single table. For STRAIGHT JOIN, the results set from the outer and the inner table are both doubled, and then the whole result set is quadrupled (2*2 = 4). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2022-02-24 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I too cannot reproduce the bug on STRAIGHT JOIN on 10.3. Spider uses id as the JOIN key and thus the problem doesn't come to visible. The difference is possibly due to the difference in parameters or the difference in the code (TSpider has original patches). However, I believe that, if we fixed the single table case, the potential bug of JOINs would be also fixed. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2022-03-01 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The bug is reproducible on 10.2. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2022-03-01 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Spider converts HA_READ_KEY_EXACT to the equality (=) but the conversion is not necessarily correct. HA_READ_KEY_EXACT rather means "find first record else error". Thus, converting = to HA_READ_KEY_EXACT is always correct but not vice versa. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2022-03-01 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
This is just an idea but importing the implementation of ha_federatedx::create_where_from_key() possibly fixes the issue. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2022-03-15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I pushed a fix for the bug. I believe it works but it affects wrappers other than mysql/mariadb. So, I will think some more about how it should be fixed. https://github.com/MariaDB/server/commit/d01959f78cc7f2b1b3f30d00f774c99e368702c9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2022-05-17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The patch converts string key equalities to LIKE conditions but the conversion is unnecessary or even harmful if a key is non-prefixed. Tencent reported that they tried the above patch and suffered from significant performance degradation. The problem is raised in the case where Spider table's primary key is on VARCHAR field and the table is partitioned. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2022-06-29 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
holyfoot Please review: https://github.com/MariaDB/server/commit/da5aff18d6321ffc24677573e47277f0d7a25a79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alexey Botchkov [ 2022-08-15 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
ok to push with one proposed correction (see the patch comment). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2022-09-06 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
This caused several conflicts on an attempted merge to 10.4 due to
Next time, please test if cherry-picking the change would cause trouble in later versions, and provide additional branches that would address those troubles, to avoid blocking a merge. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Nayuta Yanagisawa (Inactive) [ 2022-09-06 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
marko Sorry for the trouble. I will check if there are problematic conflicts. I think the following fixup fixes your merge branch: https://github.com/MariaDB/server/commit/ca57a6176787dad7bdd9878a73bf1154348e8d7f |