From a45fcdfebedbd0bb51e853e4495cc1554409e1be Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Mon, 28 Jun 2021 13:59:13 +0000 Subject: [PATCH] Avoid unnecessary information in query hints to improve query cache hit ratio --- lib/Doctrine/ORM/Tools/Pagination/Paginator.php | 2 +- lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php index 318e0ef4c69..4f203c84828 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php +++ b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php @@ -163,7 +163,7 @@ public function getIterator() $ids = array_map('current', $foundIdRows); $this->appendTreeWalker($whereInQuery, WhereInWalker::class); - $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, count($ids)); + $whereInQuery->setHint(WhereInWalker::HINT_PAGINATOR_ID_COUNT, (bool) $ids); $whereInQuery->setFirstResult(null)->setMaxResults(null); $whereInQuery->setParameter(WhereInWalker::PAGINATOR_ID_ALIAS, $ids); $whereInQuery->setCacheable($this->query->isCacheable()); diff --git a/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php b/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php index 1403fe97781..fef96b0c83c 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/WhereInWalker.php @@ -97,9 +97,9 @@ public function walkSelectStatement(SelectStatement $AST) $pathExpression = new PathExpression(PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $rootAlias, $identifierFieldName); $pathExpression->type = $pathType; - $count = $this->_getQuery()->getHint(self::HINT_PAGINATOR_ID_COUNT); + $hasIds = $this->_getQuery()->getHint(self::HINT_PAGINATOR_ID_COUNT); - if ($count > 0) { + if ($hasIds) { $arithmeticExpression = new ArithmeticExpression(); $arithmeticExpression->simpleArithmeticExpression = new SimpleArithmeticExpression( [$pathExpression]