Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3562199
D4500.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D4500.id.diff
View Options
diff --git a/keyserver/src/fetchers/message-fetchers.js b/keyserver/src/fetchers/message-fetchers.js
--- a/keyserver/src/fetchers/message-fetchers.js
+++ b/keyserver/src/fetchers/message-fetchers.js
@@ -292,8 +292,17 @@
WHERE JSON_EXTRACT(mm.permissions, ${visibleExtractString}) IS TRUE AND
`;
query.append(selectionClause);
+ // - We specify a ridiculously high LIMIT here to force MariaDB to maintain
+ // the ORDER BY. Otherwise the query optimizer will assume that the order
+ // doesn't matter because the outer query doesn't have an ORDER BY.
+ // - Setting an ORDER BY on the outer query won't work because our quirky
+ // counting logic in the SELECT would be executed before the ORDER, on the
+ // unsorted results from the inner query.
+ // - More details available here:
+ // https://mariadb.com/kb/en/why-is-order-by-in-a-from-subquery-ignored/
query.append(SQL`
ORDER BY m.thread, m.time DESC
+ LIMIT 18446744073709551615
) x
) y
WHERE y.number <= ${numberPerThread}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 28, 10:07 AM (8 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2725575
Default Alt Text
D4500.id.diff (1 KB)
Attached To
Mode
D4500: [keyserver] Force sorting of inner fetchMessageInfos query on MariaDB
Attached
Detach File
Event Timeline
Log In to Comment