Although the current sorting mechanism seems to be reasonably fast already, there's an optimization that could make it even faster.
As it stands today, any difference between the requested order and the order provided by the selected index leads to a complete re-ordering of results. However, there are cases in which partial re-ordering would be a better pick. For example, a requested ordering of ['subject', 'object'] against the index ['subject', 'predicate', 'object', 'graph'] would be better served by re-ordering quads _per each value ofsubject`_. This likely wouldn't make a dramatic difference in terms of total sorting time but it would lead to the sorting iterator beginning to emit quads much faster.
Comunica has already implemented sorting based on sliding windows, although its windows are defined by their length rather than by the value of a given term/variable.
Although the current sorting mechanism seems to be reasonably fast already, there's an optimization that could make it even faster.
As it stands today, any difference between the requested order and the order provided by the selected index leads to a complete re-ordering of results. However, there are cases in which partial re-ordering would be a better pick. For example, a requested ordering of
['subject', 'object']
against the index['subject', 'predicate', 'object', 'graph'] would be better served by re-ordering quads _per each value of
subject`_. This likely wouldn't make a dramatic difference in terms of total sorting time but it would lead to the sorting iterator beginning to emit quads much faster.Comunica has already implemented sorting based on sliding windows, although its windows are defined by their length rather than by the value of a given term/variable.