r44584 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44583‎ | r44584 | r44585 >
Date:17:04, 14 December 2008
Author:catrope
Status:ok (Comments)
Tags:
Comment:
API: (bug 16549) Kill a filesort in list=allpages&apfilterlanglinks=withlanglinks by replacing DISTINCT with GROUP BY. Of course GROUP BY page_namespace, page_title would suffice on MySQL, but Postgres will reportedly whine about that being against the SQL standard. Using GROUP BY on all selected fields instead (should please pgsql) and taking care that page_namespace, page_title is on front, which shouldn't cause a filesort is MySQL is smart enough (5.0 is, let's just hope 4.1 is too)
Modified paths:
  • /trunk/phase3/includes/api/ApiPageSet.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryAllpages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryAllpages.php
@@ -67,6 +67,16 @@
6868 if (isset ($params['prefix']))
6969 $this->addWhere("page_title LIKE '" . $db->escapeLike($this->titlePartToKey($params['prefix'])) . "%'");
7070
 71+ if (is_null($resultPageSet)) {
 72+ $selectFields = array (
 73+ 'page_namespace',
 74+ 'page_title',
 75+ 'page_id'
 76+ );
 77+ } else {
 78+ $selectFields = $resultPageSet->getPageTableFields();
 79+ }
 80+ $this->addFields($selectFields);
7181 $forceNameTitleIndex = true;
7282 if (isset ($params['minsize'])) {
7383 $this->addWhere('page_len>=' . intval($params['minsize']));
@@ -106,21 +116,15 @@
107117 } else if($params['filterlanglinks'] == 'withlanglinks') {
108118 $this->addTables('langlinks');
109119 $this->addWhere('page_id=ll_from');
110 - $this->addOption('DISTINCT');
 120+ $this->addOption('STRAIGHT_JOIN');
 121+ // We have to GROUP BY
 122+ $this->addOption('GROUP BY', implode(', ', $selectFields));
111123 $forceNameTitleIndex = false;
112124 }
113125 if ($forceNameTitleIndex)
114126 $this->addOption('USE INDEX', 'name_title');
115127
116 - if (is_null($resultPageSet)) {
117 - $this->addFields(array (
118 - 'page_id',
119 - 'page_namespace',
120 - 'page_title'
121 - ));
122 - } else {
123 - $this->addFields($resultPageSet->getPageTableFields());
124 - }
 128+
125129
126130 $limit = $params['limit'];
127131 $this->addOption('LIMIT', $limit+1);
Index: trunk/phase3/includes/api/ApiPageSet.php
@@ -92,10 +92,11 @@
9393 */
9494 public function getPageTableFields() {
9595 // Ensure we get minimum required fields
 96+ // DON'T change this order
9697 $pageFlds = array (
 98+ 'page_namespace' => null,
 99+ 'page_title' => null,
97100 'page_id' => null,
98 - 'page_namespace' => null,
99 - 'page_title' => null
100101 );
101102
102103 // only store non-default fields

Follow-up revisions

RevisionCommit summaryAuthorDate
r44586Follow-up to r44584: finishing comment.catrope17:44, 14 December 2008

Comments

#Comment by Aaron Schulz (talk | contribs)   19:03, 15 December 2008

Why does STRAIGHT_JOIN have an underscore?

#Comment by Catrope (talk | contribs)   19:07, 15 December 2008

Because it does? See includes/db/Database.php:967

Status & tagging log