Last modified: 2012-11-18 12:44:22 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T43283, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 41283 - optimize globalimagelinks query
optimize globalimagelinks query
Status: RESOLVED FIXED
Product: MediaWiki extensions
Classification: Unclassified
GlobalUsage (Other open bugs)
master
All All
: Unprioritized normal (vote)
: ---
Assigned To: Nobody - You can work on this!
: performance
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-10-22 22:30 UTC by Asher Feldman
Modified: 2012-11-18 12:44 UTC (History)
2 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Asher Feldman 2012-10-22 22:30:24 UTC
The following query type can be slow on commons, especially if globalimagelinks isn't in ram (in which case it can take 80 seconds instead 1):

mysql> explain SELECT /* GlobalUsageQuery::execute */  gil_to,gil_wiki,gil_page,gil_page_namespace_id,gil_page_namespace,gil_page_title  FROM `globalimagelinks`  WHERE gil_to = 'Flag_of_France.svg' AND (gil_wiki != 'dewiki')  ORDER BY gil_to ASC, gil_wiki ASC, gil_page ASC LIMIT 51\G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: globalimagelinks
         type: range
possible_keys: PRIMARY,globalimagelinks_wiki,globalimagelinks_wiki_nsid_title
          key: PRIMARY
      key_len: 291
          ref: NULL
         rows: 1544156
        Extra: Using where; Using filesort
1 row in set (0.00 sec)

The primary key of globalimagelinks is: PRIMARY KEY (`gil_to`,`gil_wiki`,`gil_page`), which means the data is naturally stored in "gil_to ASC, gil_wiki ASC, gil_page ASC" sorting.  The ORDER BY doesn't actually effect the query response but does still trigger the filesort.  In my tests, removing it resulted in a 10x speed increase, and matching results.
Comment 1 Sam Reed (reedy) 2012-10-23 00:54:09 UTC
So you're just suggesting drop the explicit order by if it's ASC, but add it if it's DESC?

https://gerrit.wikimedia.org/r/29524
Comment 2 Sam Reed (reedy) 2012-10-23 00:56:02 UTC
mysql> explain SELECT   gil_to,gil_wiki,gil_page,gil_page_namespace_id,gil_page_namespace,gil_page_title  FROM `globalimagelinks`  WHERE gil_to = 'Flag_of_France.svg' AND (gil_wiki != 'dewiki')  ORDER BY gil_to ASC, gil_wiki ASC, gil_page ASC LIMIT 51\G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: globalimagelinks
         type: range
possible_keys: PRIMARY,globalimagelinks_wiki,globalimagelinks_wiki_nsid_title
          key: PRIMARY
      key_len: 291
          ref: NULL
         rows: 1371752
        Extra: Using where; Using filesort
1 row in set (0.00 sec)

mysql> explain SELECT   gil_to,gil_wiki,gil_page,gil_page_namespace_id,gil_page_namespace,gil_page_title  FROM `globalimagelinks`  WHERE gil_to = 'Flag_of_France.svg' AND (gil_wiki != 'dewiki') LIMIT 51\G   *************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: globalimagelinks
         type: range
possible_keys: PRIMARY,globalimagelinks_wiki,globalimagelinks_wiki_nsid_title
          key: PRIMARY
      key_len: 291
          ref: NULL
         rows: 1371752
        Extra: Using where
1 row in set (0.00 sec)

mysql> explain SELECT   gil_to,gil_wiki,gil_page,gil_page_namespace_id,gil_page_namespace,gil_page_title  FROM `globalimagelinks`  WHERE gil_to = 'Flag_of_France.svg' AND (gil_wiki != 'dewiki')  ORDER BY gil_to DESC, gil_wiki DESC, gil_page DESC LIMIT 51\G
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: globalimagelinks
         type: range
possible_keys: PRIMARY,globalimagelinks_wiki,globalimagelinks_wiki_nsid_title
          key: PRIMARY
      key_len: 291
          ref: NULL
         rows: 1371752
        Extra: Using where; Using filesort
1 row in set (0.00 sec)
Comment 3 db [inactive,noenotif] 2012-11-18 12:44:22 UTC
(In reply to comment #1)
> So you're just suggesting drop the explicit order by if it's ASC, but add it if
> it's DESC?
> https://gerrit.wikimedia.org/r/29524

Status Merged

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links