$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__);