diff --git a/core/modules/node/src/Plugin/Search/NodeSearch.php b/core/modules/node/src/Plugin/Search/NodeSearch.php
index 83140c1..4fc3d55 100644
--- a/core/modules/node/src/Plugin/Search/NodeSearch.php
+++ b/core/modules/node/src/Plugin/Search/NodeSearch.php
@@ -206,6 +206,7 @@ protected function findResults() {
     // Build matching conditions.
     $query = $this->database
       ->select('search_index', 'i', array('target' => 'replica'))
+      // Apply pager extender last to run first to properly count.
       ->extend('Drupal\search\SearchQuery')
       ->extend('Drupal\Core\Database\Query\PagerSelectExtender');
     $query->join('node_field_data', 'n', 'n.nid = i.sid');
diff --git a/core/modules/search/src/SearchQuery.php b/core/modules/search/src/SearchQuery.php
index de679c2..4bd0a35 100644
--- a/core/modules/search/src/SearchQuery.php
+++ b/core/modules/search/src/SearchQuery.php
@@ -11,6 +11,7 @@
 
 use Drupal\Component\Utility\Unicode;
 use Drupal\Core\Database\Query\SelectExtender;
+use Drupal\Core\Database\Query\SelectInterface;
 use Drupal\Core\Database\StatementEmpty;
 
 /**
@@ -463,6 +464,21 @@ public function prepareAndNormalize() {
   }
 
   /**
+   * {@inhertidoc}
+   */
+  public function preExecute(SelectInterface $query = NULL) {
+    if (!$this->executedPrepare) {
+      $this->prepareAndNormalize();
+    }
+
+    if (!$this->normalize) {
+      return FALSE;
+    }
+
+    return parent::preExecute($query);
+  }
+
+  /**
    * Adds a custom score expression to the search query.
    *
    * Score expressions are used to order search results. If no calls to
@@ -521,9 +537,8 @@ public function addScore($score, $arguments = array(), $multiply = FALSE) {
   /**
    * Executes the search.
    *
-   * If not already done, this calls prepareAndNormalize() first. Then the
-   * complex conditions are applied to the query including score expressions
-   * and ordering.
+   * The complex conditions are applied to the query including score
+   * expressions and ordering.
    *
    * Error and warning conditions can apply. Call getStatus() after calling
    * this method to retrieve them.
@@ -532,14 +547,8 @@ public function addScore($score, $arguments = array(), $multiply = FALSE) {
    *   A query result set containing the results of the query.
    */
   public function execute() {
-
-    if (!$this->executedPrepare) {
-      $this->prepareAndNormalize();
-    }
-
-    if (!$this->normalize) {
-      // There were no keyword matches, so return an empty result set.
-      return new StatementEmpty();
+    if (!$this->preExecute($this)) {
+      return NULL;
     }
 
     // Add conditions to the query.
@@ -606,8 +615,6 @@ public function countQuery() {
     if (count($this->conditions)) {
       $inner->condition($this->conditions);
     }
-    // PostgreSQL requires a group by condition to prevent a GROUPING ERROR.
-    $inner->groupBy('i.sid');
 
     // Remove existing fields and expressions, they are not needed for a count
     // query.
