From 684a4c3fb73b9bfd41775260c2bb98ce219494f3 Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Sun, 14 Dec 2008 17:04:24 +0000 Subject: [PATCH] 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) --- includes/api/ApiPageSet.php | 5 +++-- includes/api/ApiQueryAllpages.php | 24 ++++++++++++++---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index 67b261e11d..e846f30e2f 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -92,10 +92,11 @@ class ApiPageSet extends ApiQueryBase { */ public function getPageTableFields() { // Ensure we get minimum required fields + // DON'T change this order $pageFlds = array ( - 'page_id' => null, 'page_namespace' => null, - 'page_title' => null + 'page_title' => null, + 'page_id' => null, ); // only store non-default fields diff --git a/includes/api/ApiQueryAllpages.php b/includes/api/ApiQueryAllpages.php index 3211a20e11..f26335f903 100644 --- a/includes/api/ApiQueryAllpages.php +++ b/includes/api/ApiQueryAllpages.php @@ -67,6 +67,16 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { if (isset ($params['prefix'])) $this->addWhere("page_title LIKE '" . $db->escapeLike($this->titlePartToKey($params['prefix'])) . "%'"); + if (is_null($resultPageSet)) { + $selectFields = array ( + 'page_namespace', + 'page_title', + 'page_id' + ); + } else { + $selectFields = $resultPageSet->getPageTableFields(); + } + $this->addFields($selectFields); $forceNameTitleIndex = true; if (isset ($params['minsize'])) { $this->addWhere('page_len>=' . intval($params['minsize'])); @@ -106,21 +116,15 @@ class ApiQueryAllpages extends ApiQueryGeneratorBase { } else if($params['filterlanglinks'] == 'withlanglinks') { $this->addTables('langlinks'); $this->addWhere('page_id=ll_from'); - $this->addOption('DISTINCT'); + $this->addOption('STRAIGHT_JOIN'); + // We have to GROUP BY + $this->addOption('GROUP BY', implode(', ', $selectFields)); $forceNameTitleIndex = false; } if ($forceNameTitleIndex) $this->addOption('USE INDEX', 'name_title'); - if (is_null($resultPageSet)) { - $this->addFields(array ( - 'page_id', - 'page_namespace', - 'page_title' - )); - } else { - $this->addFields($resultPageSet->getPageTableFields()); - } + $limit = $params['limit']; $this->addOption('LIMIT', $limit+1); -- 2.20.1