Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Zend\Paginator\Adapter\DbSelect

First attempt at using subselect to calculate full count
  • Loading branch information...
commit c49d65908cfc5be1f5070fba65b8b820bdbdd9c9 1 parent 916dd0d
@ralphschindler ralphschindler authored
Showing with 4 additions and 10 deletions.
  1. +4 −10 library/Zend/Paginator/Adapter/DbSelect.php
View
14 library/Zend/Paginator/Adapter/DbSelect.php
@@ -107,18 +107,12 @@ public function count()
$select->reset(Select::LIMIT);
$select->reset(Select::OFFSET);
$select->reset(Select::ORDER);
- $select->reset(Select::GROUP);
- // get join information, clear, and repopulate without columns
- $joins = $select->getRawState(Select::JOINS);
- $select->reset(Select::JOINS);
- foreach ($joins as $join) {
- $select->join($join['name'], $join['on'], array(), $join['type']);
- }
-
- $select->columns(array('c' => new Expression('COUNT(1)')));
+ $countSelect = new Select;
+ $countSelect->columns(array('c' => new Expression('COUNT(1)')));
+ $countSelect->from(array('original_select' => $select));
- $statement = $this->sql->prepareStatementForSqlObject($select);
+ $statement = $this->sql->prepareStatementForSqlObject($countSelect);
$result = $statement->execute();
$row = $result->current();

3 comments on commit c49d659

@bdewong

To me it would seem that this change would dramatically increase the processing time in some cases. In the simplest case, I used a basic full table SELECT. In this scenario, the subquery will grab all the information from the table, when perform a count on that instead of providing just a simple count of the data we need. Is that not correct?
Thanks,
Brent

@ralphschindler
Collaborator

Perhaps, but admittedly performance was not the top priority. Correctness and cross-db platform interoperability were higher priorities. That said, there is a great PR (#5518) that will allow for custom Select objects during pagination.

@malteriesch

As I believe the correctness problem is mainly down to problems with queries having group by, maybe we could simply check if there are any group -bys and then select the paginator strategy accordingly: without sub-select if there are no group-bys and using the sub select if there are)..?

Please sign in to comment.
Something went wrong with that request. Please try again.