Patch to change the ORDER BY in the queries to match that expected by the continue handling
For iwlinks, the continue parameter implies ORDER BY iwl_from, iwl_prefix, iwl_title. However, this does not match the actual ordering in two of the three cases:
- When iwprefix is not given, the query is ORDER BY iwl_from, iwl_prefix (or ORDER BY iwl_prefix when iwl_from is constant). iwl_title is not sorted, so if the database would want to return three titles in the order A, C, B, with iwlimit=1 it would return A and set continue to C. When continuing, it would skip B because C > B.
- When iwprefix is given but iwtitle is not given, the query is ORDER BY iwl_title, iwl_from, which is backwards (iwl_prefix need not be included, as it is constant). This is very easy to see the problem: just create pages A and B where B has an interwiki link that sorts between two interwiki links in A. https://en.wikipedia.org/w/api.php?format=jsonfm&action=query&prop=iwlinks&titles=A|C&iwprefix=wikisource&iwlimit=1 illustrates this at the moment.
- When both iwprefix and iwltitle are specified, the query is ORDER BY iwl_from. This is fine because iwl_prefix and iwl_title are constant in the query.
The langlinks module has a similar structure, but here case 1 is not a problem because (ll_from, ll_prefix) is a unique key. Case 2 *is* still an issue.
The simple fix would be to change the queries so the ordering matches that implied by the continue parameter in all cases (see patch). I don't know if this will make MySQL filesort, however.
Version: 1.20.x
Severity: normal
attachment diff ignored as obsolete