Faster count query using getFullCount except getCount

This commit is contained in:
bethrezen 2014-09-30 17:55:09 +04:00
parent d9d4cc4c7b
commit c3b9d78427

View File

@ -616,8 +616,13 @@ class Query extends Component implements QueryInterface
public function count($q = '*', $db = null) public function count($q = '*', $db = null)
{ {
$this->select = '1';
$this->limit(1);
$this->offset(0);
$statement = $this->createCommand($db); $statement = $this->createCommand($db);
$statement->setCount(true); $statement->setFullCount(true);
$statement->setBatchSize(1);
$token = $this->getRawAql($statement); $token = $this->getRawAql($statement);
Yii::info($token, 'devgroup\arangodb\Query::query'); Yii::info($token, 'devgroup\arangodb\Query::query');
try { try {
@ -628,7 +633,7 @@ class Query extends Component implements QueryInterface
Yii::endProfile($token, 'devgroup\arangodb\Query::query'); Yii::endProfile($token, 'devgroup\arangodb\Query::query');
throw new \Exception($ex->getMessage(), (int) $ex->getCode(), $ex); throw new \Exception($ex->getMessage(), (int) $ex->getCode(), $ex);
} }
return $cursor->getCount(); return $cursor->getFullCount();
} }
public function exists($db = null) public function exists($db = null)