diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
index 259d240..c826714 100644
--- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
+++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
@@ -1634,10 +1634,12 @@ public function countFieldData($storage_definition, $as_bool = FALSE) {
       foreach ($storage_definition->getColumns() as $column_name => $data) {
         $or->isNotNull($table_mapping->getFieldColumnName($storage_definition, $column_name));
       }
-      $query
-        ->condition($or)
-        ->fields('t', array('entity_id'))
-        ->distinct(TRUE);
+      $query->condition($or);
+      if (!$as_bool) {
+        $query
+          ->fields('t', array('entity_id'))
+          ->distinct(TRUE);
+      }
     }
     elseif ($table_mapping->allowsSharedTableStorage($storage_definition)) {
       // Ascertain the table this field is mapped too.
diff --git a/core/modules/field/src/Tests/FieldDataCountTest.php b/core/modules/field/src/Tests/FieldDataCountTest.php
index aef5e7e..9edbbdb 100644
--- a/core/modules/field/src/Tests/FieldDataCountTest.php
+++ b/core/modules/field/src/Tests/FieldDataCountTest.php
@@ -8,6 +8,8 @@
 namespace Drupal\field\Tests;
 
 use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
+use Drupal\field\Entity\FieldConfig;
+use Drupal\field\Entity\FieldStorageConfig;
 
 /**
  * Tests counting field data records and the hasData() method on
@@ -146,6 +148,20 @@ public function testEntityCountAndHasData() {
    * Verify that we can count a table that contains an entry with index 0.
    */
   public function testCountWithIndex0() {
+    // Create a field that will require dedicated storage.
+    /** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
+    $field_storage = FieldStorageConfig::create(array(
+      'field_name' => 'field_int',
+      'entity_type' => 'user',
+      'type' => 'integer',
+      'cardinality' => 2,
+    ));
+    $field_storage->save();
+    FieldConfig::create(array(
+      'field_storage' => $field_storage,
+      'bundle' => 'user',
+    ))->save();
+
     // Create an entry for the anonymous user, who has user ID 0.
     $user = $this->storageUser
       ->create(array(
@@ -153,11 +169,17 @@ public function testCountWithIndex0() {
         'name' => 'anonymous',
         'mail' => NULL,
         'status' => FALSE,
+        'field_int' => 42,
       ));
     $user->save();
 
+    // Test shared table storage.
     $storage = $user->getFieldDefinition('name')->getFieldStorageDefinition();
     $this->assertIdentical(TRUE, $this->storageUser->countFieldData($storage, TRUE));
+
+    // Test dedicated table storage.
+    $storage = $user->getFieldDefinition('field_int')->getFieldStorageDefinition();
+    $this->assertIdentical(TRUE, $this->storageUser->countFieldData($storage, TRUE));
   }
 
 }
