[MDEV-26787] Document that NATURAL_SORT_KEY virtual column should be longer than the base column (and other notes) Created: 2021-10-07 Updated: 2021-10-19 Resolved: 2021-10-19 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Documentation |
| Fix Version/s: | N/A |
| Type: | Task | Priority: | Critical |
| Reporter: | Elena Stepanova | Assignee: | Ian Gilfillan |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
Contrary to the example in the blog post about natural sort, the virtual column should be longer than the base column. This is due to the specifics of the design, which makes values in the virtual columns be longer than the originally inserted values. We can't know at the table creation how much longer it should be, so I suppose there is no point throwing an error or a warning upon table creation, but at least it should be documented. Otherwise, even a simple example like the on in the blog post only works by pure chance. Here is the same example, only instead of ('a1') it inserts ('a10'):
This is because both a11 and a10 cause an overflow in column k. |
| Comments |
| Comment by Vladislav Vaintroub [ 2021-10-07 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I doubt there could be any design where you get this function to be smaller or the same size as the original source string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2021-10-07 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Sure, but users can't know it, hence "documentation". There is no documentation for the virtual column part yet (or I haven't found it), thus not a bug, but a task to make a mention of it when the time comes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2021-10-11 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Some optional usage examples for documentation (just suggestions). While it is not the main idea of natural sort, it is handy for sorting ENUM values. Usually they are sorted by their numeric value, which is not necessarily what the user wants. Natural sort sorts them by their text value instead.
On the other hand, for types like INET6 it is unlikely to be useful:
While it is technically correct, it's not very meaningful in relation to IPv6 addresses. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2021-10-11 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
By current design of
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Vladislav Vaintroub [ 2021-10-11 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The order looks strange, because you expect numbers to be sorted as fractions. The fractions are not handled, so the order is just not deterministic, in presence of leading zeros. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2021-10-11 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
No, it is not that at all. I have a problem with natural sort and fractions, but it doesn't apply here. I put a period because it's easier for me to look at, but it's not important for the subject. Let's have it this way:
The result above is our usual "unnatural" sort. There is nothing special about it.
The result above, technically "natural sort", still looks strange. It is strange not because it resembles fractions, but because it is not ordered at all within each equality group, e.g. the sequence a01 a001 a1 is not ordered. It is by design, because for all of them the functon value is a01, so the order can be random. This is what I suggest as a workaround for those who needs it ordered.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ian Gilfillan [ 2021-10-19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2021-10-19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Sorry, typo, fixed. MDEV-24582 . |