diff --git a/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php b/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php
index 2216927..07be528 100644
--- a/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php
+++ b/core/modules/history/src/Plugin/views/filter/HistoryUserTimestamp.php
@@ -82,9 +82,12 @@ public function query() {
     $clause = '';
     $clause2 = '';
     if (\Drupal::moduleHandler()->moduleExists('comment')) {
-      $ces = $this->query->ensureTable('comment_entity_statistics', $this->relationship);
-      $clause = ("OR $ces.last_comment_timestamp > (***CURRENT_TIME*** - $limit)");
-      $clause2 = "OR $field < $ces.last_comment_timestamp";
+      // The table is not available if none of the content types has attached
+      // comment field.
+      if ($ces = $this->query->ensureTable('comment_entity_statistics', $this->relationship)) {
+        $clause = ("OR $ces.last_comment_timestamp > (***CURRENT_TIME*** - $limit)");
+        $clause2 = "OR $field < $ces.last_comment_timestamp";
+      }
     }
 
     // NULL means a history record doesn't exist. That's clearly new content.
diff --git a/core/modules/history/src/Tests/Views/HistoryTimestampTest.php b/core/modules/history/src/Tests/Views/HistoryTimestampTest.php
index 44f67f9..9f464d1 100644
--- a/core/modules/history/src/Tests/Views/HistoryTimestampTest.php
+++ b/core/modules/history/src/Tests/Views/HistoryTimestampTest.php
@@ -24,7 +24,7 @@ class HistoryTimestampTest extends ViewTestBase {
    *
    * @var array
    */
-  public static $modules = array('history', 'node');
+  public static $modules = array('history', 'node', 'comment');
 
   /**
    * Views used by this test.
