summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2016-01-25 12:31:23 +0100
committerAndrey Andreev <narf@devilix.net>2016-01-25 12:31:23 +0100
commit075bdb4e90d9b567cdb4db3e46410854c0437856 (patch)
tree3d586ab5d4923693f7501c3df80637228cc2b914 /system
parentb5d410530f7641ba0feb1ec0e25b4243be1fe053 (diff)
Fix #4395
Diffstat (limited to 'system')
-rw-r--r--system/database/DB_query_builder.php16
1 files changed, 15 insertions, 1 deletions
diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php
index e92c57091..c180a17e9 100644
--- a/system/database/DB_query_builder.php
+++ b/system/database/DB_query_builder.php
@@ -1379,7 +1379,16 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
$this->from($table);
}
- $result = ($this->qb_distinct === TRUE OR ! empty($this->qb_orderby))
+ // ORDER BY usage is often problematic here (most notably
+ // on Microsoft SQL Server) and ultimately unnecessary
+ // for selecting COUNT(*) ...
+ if ( ! empty($this->qb_orderby))
+ {
+ $orderby = $this->qb_orderby;
+ $this->qb_orderby = NULL;
+ }
+
+ $result = ($this->qb_distinct === TRUE)
? $this->query($this->_count_string.$this->protect_identifiers('numrows')."\nFROM (\n".$this->_compile_select()."\n) CI_count_all_results")
: $this->query($this->_compile_select($this->_count_string.$this->protect_identifiers('numrows')));
@@ -1387,6 +1396,11 @@ abstract class CI_DB_query_builder extends CI_DB_driver {
{
$this->_reset_select();
}
+ // If we've previously reset the qb_orderby values, get them back
+ elseif ( ! isset($this->qb_orderby))
+ {
+ $this->qb_orderby = $orderby;
+ }
if ($result->num_rows() === 0)
{