diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php
index 5eeb637..fe23e3f 100644
--- a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php
+++ b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php
@@ -11,6 +11,7 @@
 use PDO;
 use Drupal\Core\Cache\CacheBackendInterface;
 use Drupal\Core\Entity\Query\QueryInterface;
+use Drupal\Core\Entity\Query\Sql\Tables;
 use Drupal\Component\Uuid\Uuid;
 use Drupal\Component\Utility\NestedArray;
 use Drupal\Core\Database\Connection;
@@ -566,4 +567,11 @@ public function baseFieldDefinitions() {
   public function getQueryServiceName() {
     return 'entity.query.sql';
   }
+
+  /**
+   * Gets the appropriate tables class for the entity type.
+   */
+  public function getTables(SelectInterface $sql_query) {
+    return new Tables($sql_query);
+  }
 }
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php b/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php
index 7323586..82a5971 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php
@@ -24,7 +24,7 @@ public function compile($conditionContainer) {
     // can join tables as necessary. On the other hand, conditions need to be
     // added to the $conditionContainer object to keep grouping.
     $sqlQuery = $conditionContainer instanceof SelectInterface ? $conditionContainer : $conditionContainer->sqlQuery;
-    $tables = new Tables($sqlQuery);
+    $tables = $this->entityManager->getStorageController($this->entityType)->getTables($sqlQuery);
     foreach ($this->conditions as $condition) {
       if ($condition['field'] instanceOf ConditionInterface) {
         $sqlCondition = new SqlCondition($condition['field']->getConjunction());
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/ConditionAggregate.php b/core/lib/Drupal/Core/Entity/Query/Sql/ConditionAggregate.php
index cd83691..f1539c3 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/ConditionAggregate.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/ConditionAggregate.php
@@ -26,7 +26,7 @@ public function compile($conditionContainer) {
     // can join tables as necessary. On the other hand, conditions need to be
     // added to the $conditionContainer object to keep grouping.
     $sql_query = ($conditionContainer instanceof SelectInterface) ? $conditionContainer : $conditionContainer->sqlQuery;
-    $tables = new Tables($sql_query);
+    $tables = $this->entityManager->getStorageController($this->entityType)->getTables($sqlQuery);
     foreach ($this->conditions as $condition) {
       if ($condition['field'] instanceOf ConditionAggregateInterface) {
         $sql_condition = new Condition($condition['field']->getConjunction());
diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Query.php b/core/lib/Drupal/Core/Entity/Query/Sql/Query.php
index 6fbae92..ff50814 100644
--- a/core/lib/Drupal/Core/Entity/Query/Sql/Query.php
+++ b/core/lib/Drupal/Core/Entity/Query/Sql/Query.php
@@ -289,7 +289,7 @@ protected function result() {
    */
   protected function getSqlField($field, $langcode) {
     if (!isset($this->tables)) {
-      $this->tables = new Tables($this->sqlQuery);
+      $this->tables = $this->entityManager->getStorageController($this->entityType)->getTables($this->sqlQuery);
     }
     $base_property = "base_table.$field";
     if (isset($this->sqlFields[$base_property])) {
