Steps to Reproduce
- Using MediaWiki with SQLite, go to Special:Investigate
- Start an investigation and then go to Special:Investigate/Compare
Actual Results
A database query error has occurred. Did you forget to run your application's database schema updater after upgrading? Query: SELECT a.cuc_user,a.cuc_user_text,a.cuc_ip,a.cuc_ip_hex,a.cuc_agent,MIN(a.cuc_timestamp) AS "first_edit",MAX(a.cuc_timestamp) AS "last_edit",count(*) AS "total_edits" FROM (SELECT cuc_user,cuc_user_text,cuc_ip,cuc_ip_hex,cuc_agent,cuc_timestamp FROM cu_changes WHERE cuc_user = 1 AND cuc_type IN (0,1) ORDER BY cuc_timestamp LIMIT 50000 UNION SELECT cuc_user,cuc_user_text,cuc_ip,cuc_ip_hex,cuc_agent,cuc_timestamp FROM cu_changes WHERE cuc_user = 3 AND cuc_type IN (0,1) ORDER BY cuc_timestamp LIMIT 50000 ) AS a GROUP BY cuc_user_text,cuc_ip,cuc_agent ORDER BY cuc_user_text,cuc_ip,cuc_agent LIMIT 51 Function: IndexPager::buildQueryInfo (MediaWiki\CheckUser\ComparePager) Error: 1 ORDER BY clause should come after UNION not before
Expected Results
A table of results. :)
Caused By
T245499: Improve performance of Compare query for Special:Investigate
Proposed Solution
Use IDatabase::unionConditionPermutations() to generate the list of UNION queries. This should properly remove the ORDER BY and LIMIT from the query when the database doesn't support them in subqueries.
Alternative Solution
Alternatively, using IDatabase::unionSupportsOrderAndLimit() to determine if we should include or exclude the ORDER BY and LIMIT from the query.