Erlang - Is there anything in Mnesia similar to ORDER BY in mysql?

I can order the received data from mnesia, but I was wondering if it is possible to sort the data when querying from mnesia, similar to using ORDER BY in mysql

+3
source share
2 answers

If you have ordered_set, you have already sorted by key. Otherwise you can use lists:sort/2. To sort by depth inside complex structures or by many of these keys, you can speed up sorting using Schwartzian_transform , i.e. combination lists:sort/1and two lists:map/2or list comprehension. For more data, consider file_sorter.

+1

ordered_set @Hynek. , ordered_set , set Mnesia.

Set

| Operation | Average | Worst Case |
|:---------:|:-------:|:----------:|
| Space     | O(n)    | O(n)       |
| Search    | O(1)    | O(n)       |
| Insert    | O(1)    | O(n)       |
| Delete    | O(1)    | O(n)       |

| Operation | Average  | Worst Case |
|:---------:|:--------:|:----------:|
| Space     | O(n)     | O(n)       |
| Search    | O(log n) | O(n)       |
| Insert    | O(log n) | O(n)       |
| Delete    | O(log n) | O(n)       |

ordered_set , set , . , , , . , . , .

0
source

Source: https://habr.com/ru/post/1619179/


All Articles