diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index 27d778016..43c54321e 100755 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -1517,6 +1517,8 @@ public function getLimitSubquery() // add driver specific limit clause $subquery = $this->_conn->modifyLimitSubquery($table, $subquery, $this->_sqlParts['limit'], $this->_sqlParts['offset']); + // apply any outstanding indexes to the subquery before we rebuild the query parts using new Aliases + $subquery = $this->_applyIndexesToQuery($subquery); $parts = $this->_tokenizer->quoteExplode($subquery, ' ', "'", "'"); @@ -1586,6 +1588,7 @@ public function getLimitSubquery() } $subquery = implode(' ', $parts); + return $subquery; } @@ -2112,7 +2115,7 @@ public function getCountSqlQuery() . $this->_conn->quoteIdentifier('dctrn_count_query'); } - return $q; + return $this->_applyIndexesToQuery($q); } /** diff --git a/lib/Doctrine/Query/Abstract.php b/lib/Doctrine/Query/Abstract.php index a5ff0a10b..9b472b609 100755 --- a/lib/Doctrine/Query/Abstract.php +++ b/lib/Doctrine/Query/Abstract.php @@ -1059,8 +1059,6 @@ protected function _execute($params) $query = $this->_view->getSelectSql(); } - $query = $this->_applyIndexesToQuery($query); - // Get prepared SQL params for execution $params = $this->getInternalParams(); @@ -2503,8 +2501,7 @@ protected function _applyIndexesToQuery($sql) } } } - // Empty the index part array to prevent us from accidentally appending twice. - $this->_index_parts = []; + return $sql; } diff --git a/lib/Doctrine/RawSql.php b/lib/Doctrine/RawSql.php old mode 100644 new mode 100755 index 199fde9b8..10f844f3c --- a/lib/Doctrine/RawSql.php +++ b/lib/Doctrine/RawSql.php @@ -283,7 +283,7 @@ public function getSqlQuery($params = array()) if ( ! empty($string)) { array_pop($this->_sqlParts['where']); } - return $q; + return $this->_applyIndexesToQuery($q); } /** @@ -326,7 +326,7 @@ public function getCountSqlQuery($params = array()) array_pop($this->_sqlParts['where']); } - return $q; + return $this->_applyIndexesToQuery($q); } /**