From 3ca55a03ad9df6b5d5bfc0447d9fe1bd9bbea32e Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Tue, 13 May 2008 10:39:01 +0000 Subject: [PATCH] (bug 14012) prop=templates filesorts under some conditions --- includes/api/ApiQueryLinks.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/includes/api/ApiQueryLinks.php b/includes/api/ApiQueryLinks.php index 5a2cf07441..b27be256ee 100644 --- a/includes/api/ApiQueryLinks.php +++ b/includes/api/ApiQueryLinks.php @@ -84,7 +84,18 @@ class ApiQueryLinks extends ApiQueryGeneratorBase { $this->addTables($this->table); $this->addWhereFld($this->prefix . '_from', array_keys($this->getPageSet()->getGoodTitles())); $this->addWhereFld($this->prefix . '_namespace', $params['namespace']); - $this->addOption('ORDER BY', str_replace('pl_', $this->prefix . '_', 'pl_from, pl_namespace, pl_title')); + + # Here's some MySQL craziness going on: if you use WHERE foo='bar' + # and later ORDER BY foo MySQL doesn't notice the ORDER BY is pointless + # but instead goes and filesorts, because the index for foo was used + # already. To work around this, we drop constant fields in the WHERE + # clause from the ORDER BY clause + $order = array(); + if(count($this->getPageSet()->getGoodTitles()) != 1) + $order[] = "{$this->prefix}_from"; + // pl_namespace is always constant + $order[] = "{$this->prefix}_title"; + $this->addOption('ORDER BY', implode(", ", $order)); $db = $this->getDB(); $res = $this->select(__METHOD__); -- 2.20.1