Page MenuHomePhabricator

SQLite Database Error on Special:Investigate/Compare
Closed, ResolvedPublicBUG REPORT

Description

Steps to Reproduce

  1. Using MediaWiki with SQLite, go to Special:Investigate
  2. 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.

Event Timeline

dbarratt renamed this task from SQLite Database Error on Special:Investigate to SQLite Database Error on Special:Investigate/Compare.Mar 4 2020, 5:21 PM
Niharika moved this task from Untriaged to Triage/To be Estimated on the Anti-Harassment board.

Change 576945 had a related patch set uploaded (by Dbarratt; owner: Dbarratt):
[mediawiki/extensions/CheckUser@master] Fix SQLite support with improved query on Special:Investigate

https://gerrit.wikimedia.org/r/576945

Change 576945 merged by jenkins-bot:
[mediawiki/extensions/CheckUser@master] Fix SQLite support with improved query on Special:Investigate

https://gerrit.wikimedia.org/r/576945

dom_walden subscribed.

I have got this running on my local Docker version, with SQLite and CentralAuth setup (MediaWiki 1.35.0-alpha (2419efb) 07:31, 25 March 2020; CheckUser 2.5 (d52637c) 08:02, 23 March 2020).

I can submit an investigation and see Preliminary Check and Compare results without database errors.

I compared the SQL query being run on my SQLite MW to my vagrant MW with MySQL, after:

  • Going to the Compare tab
  • Going to the second page
  • Applying a filter

The SQL queries on both MWs were the same apart from the SQLite version not including ORDER BY cuc_timestamp DESC LIMIT 50000/100000 in the subqueries.

This means, using SQLite, you won't take advantage of the performance improvements of T245499.

The results you get on SQLite might be different than other databases, as there is no ORDER or LIMIT to the data being fetched.