Page MenuHomePhabricator

When paging by Ferret "rank", page using "HAVING rank > ...", not "WHERE rank > ..."
ClosedPublic

Authored by epriestley on Mar 19 2019, 6:24 PM.
Tags
None
Referenced Files
F14101048: D20298.id.diff
Tue, Nov 26, 3:45 PM
Unknown Object (File)
Wed, Nov 20, 4:38 AM
Unknown Object (File)
Tue, Nov 19, 11:00 PM
Unknown Object (File)
Sat, Nov 9, 3:30 PM
Unknown Object (File)
Sat, Nov 9, 3:30 PM
Unknown Object (File)
Sat, Nov 9, 3:30 PM
Unknown Object (File)
Wed, Nov 6, 12:17 AM
Unknown Object (File)
Oct 26 2024, 2:27 AM
Subscribers
None

Details

Summary

Ref T13091. The Ferret "rank" column is a function of the query text and looks something like SELECT ..., 2 + 2 AS rank, ....

You can't apply conditions to this kind of dynamic column with a WHERE clause: you get a slightly unhelpful error like "column rank unknown in where clause". You must use HAVING:

mysql> SELECT 2 + 2 AS x WHERE x = 4;
ERROR 1054 (42S22): Unknown column 'x' in 'where clause'
mysql> SELECT 2 + 2 AS x HAVING x = 4;
+---+
| x |
+---+
| 4 |
+---+
1 row in set (0.00 sec)

Add a flag to paging column definitions to let them specify that they must be applied with HAVING, then apply the whole paging clause with HAVING if any column requires HAVING.

Test Plan
  • In Maniphest, ran a fulltext search matching more than 100 results, ordered by "Relevance", then clicked "Next Page".
  • Before patch: query with ... WHERE rank > 123 OR ... caused MySQL error because rank is not a WHERE-able column.
  • After patch: query builds as ... HAVING rank > 123 OR ..., pages properly, no MySQL error.

Diff Detail

Repository
rP Phabricator
Lint
Lint Not Applicable
Unit
Tests Not Applicable