diff --git a/core/lib/Drupal/Core/Database/Query/PagerSelectExtender.php b/core/lib/Drupal/Core/Database/Query/PagerSelectExtender.php
index 0f023e7..15a4b1f 100644
--- a/core/lib/Drupal/Core/Database/Query/PagerSelectExtender.php
+++ b/core/lib/Drupal/Core/Database/Query/PagerSelectExtender.php
@@ -16,6 +16,10 @@
  *
  * This is the "default" pager mechanism.  It creates a paged query with a fixed
  * number of entries per page.
+ *
+ * When adding this extender along with other extenders, be sure to add
+ * PagerSelectExtender last, so that its range and count are based on the full
+ * query.
  */
 class PagerSelectExtender extends SelectExtender {
 
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.
