[MDEV-21922] Allow packing addon fields even if they don't honour max_length_for_sort_data Created: 2020-03-12 Updated: 2020-03-17 Resolved: 2020-03-15 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.5 |
| Fix Version/s: | 10.5.2 |
| Type: | Bug | Priority: | Major |
| Reporter: | Varun Gupta (Inactive) | Assignee: | Varun Gupta (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
When we pick the strategy of using addon fields while doing filesort, we try to check if one can pack the addon fields or not.
This means if the number of bytes becomes greater than max_length_for_sort_data by adding the size of length field for This issue was found during the performance testing for packed sort keys |
| Comments |
| Comment by Varun Gupta (Inactive) [ 2020-03-12 ] | ||||||||||||||||||||||||||
|
The slowdown in peformance was seen while benchmarking | ||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2020-03-12 ] | ||||||||||||||||||||||||||
|
So without the patch
With the patch where we pack addon fields:
| ||||||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2020-03-12 ] | ||||||||||||||||||||||||||
|
Patch | ||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2020-03-12 ] | ||||||||||||||||||||||||||
|
I'm debugging this example:
in filesort_use_addons():
Here, sortlength=401, *length=609. 401 is the length of strxfrm() image of the column. That is, we assume non-packed sort keys here. Then, execution enters Sort_param::try_to_pack_sortkeys() and at the end of that function it sets:
Here, sort_length = 607, addon_length = 609. Then, execution enters Sort_param::try_to_pack_addons(), where the check
fails, because rec_length=1216 while max_length_for_sort_data=1024 (sz=2 but that doesn't matter). | ||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2020-03-12 ] | ||||||||||||||||||||||||||
|
Does filesort_use_addons() do wrong computation? One may argue that this computation is fine, because: use of unpacked key length in filesort_use_addons() is fine, because unpacked key length is a good upper bound or packed key length. (One can expect the code to not switch to packed keys if they are bigger than unpacked ones). The second check fails, because we are using maximum possible length of the packed sort key there. For utf8_general_ci, the original string form can be longer than its mem-comparable form (note that this is rarely achieved in practice. Also note that for other collations, e.g. utf8_unicode_ci, this is not the case). |