diff --git a/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php b/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
index 0eac141..3fe5e08 100644
--- a/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
+++ b/core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
@@ -29,6 +29,13 @@
   protected $query;
 
   /**
+   * If the query has been already prepared.
+   *
+   * @var bool
+   */
+  protected $isQueryPrepared = FALSE;
+
+  /**
    * The database object.
    *
    * @var \Drupal\Core\Database\Connection
@@ -145,11 +152,13 @@ protected function select($table, $alias = NULL, array $options = array()) {
    *   The query with additional tags and metadata.
    */
   protected function prepareQuery() {
-    $this->query = clone $this->query();
-    $this->query->addTag('migrate');
-    $this->query->addTag('migrate_' . $this->migration->id());
-    $this->query->addMetaData('migration', $this->migration);
-
+    if (!$this->isQueryPrepared) {
+      $this->query = clone $this->query();
+      $this->query->addTag('migrate');
+      $this->query->addTag('migrate_' . $this->migration->id());
+      $this->query->addMetaData('migration', $this->migration);
+      $this->isQueryPrepared = TRUE;
+    }
     return $this->query;
   }
 
@@ -232,8 +241,9 @@ protected function initializeIterator() {
   /**
    * {@inheritdoc}
    */
-  public function count() {
-    return $this->query()->countQuery()->execute()->fetchField();
+  public function count($refresh = FALSE) {
+    $query = clone $this->prepareQuery();
+    return $query->countQuery()->execute()->fetchField();
   }
 
   /**
