diff -u b/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install
--- b/core/modules/taxonomy/taxonomy.install
+++ b/core/modules/taxonomy/taxonomy.install
@@ -8,6 +8,7 @@
 use Drupal\Core\Entity\Sql\SqlEntityStorageInterface;
 use Drupal\Core\Field\BaseFieldDefinition;
 use Drupal\Core\Site\Settings;
+use Drupal\node\NodeInterface;
 
 /**
  * Convert the custom taxonomy term hierarchy storage to a default storage.
@@ -252,36 +253,37 @@
 /**
  * Add unpublished nodes to the taxonomy index table.
  */
-function taxonomy_update_8602(&$sandbox) {
+function taxonomy_update_8703(&$sandbox) {
+  $database = \Drupal::database();
+
   if (!isset($sandbox['total'])) {
     // Initialize state for future calls.
     $sandbox['last'] = 0;
     $sandbox['count'] = 0;
 
-    $query = db_select('node_field_data', 'n')
-      ->condition('n.status', NODE_NOT_PUBLISHED);
+    $query = $database->select('node_field_data', 'n')
+      ->condition('n.status', NodeInterface::NOT_PUBLISHED);
     $sandbox['total'] = $query->countQuery()->execute()->fetchField();
   }
 
   if ($sandbox['total']) {
     // Operate on every unpublished node, in batches.
     $batch_size = 100;
-    $query = db_select('node_field_data', 'n');
+    $query = $database->select('node_field_data', 'n');
     $query
-      ->fields('n', array('nid'))
+      ->fields('n', ['nid'])
       ->condition('n.nid', $sandbox['last'], '>')
-      ->condition('n.status', NODE_NOT_PUBLISHED)
+      ->condition('n.status', NodeInterface::NOT_PUBLISHED)
       ->orderBy('n.nid', 'ASC')
       ->range(0, $batch_size);
-    $records = $query->execute();
+    $nids = $query->execute()->fetchCol();
+    $node_storage = \Drupal::entityTypeManager()->getStorage('node');
     // Build the taxonomy index for each node.
-    foreach ($records as $record) {
-      $node = node_load($record->nid);
-
+    foreach ($node_storage->loadMultiple($nids) as $node) {
       // Delete node index to avoid integrity constraint violation errors.
       taxonomy_delete_node_index($node);
       taxonomy_build_node_index($node);
-      $sandbox['last'] = $record->nid;
+      $sandbox['last'] = $node->id();
     }
     $sandbox['count'] += $batch_size;
   }
diff -u b/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module
--- b/core/modules/taxonomy/taxonomy.module
+++ b/core/modules/taxonomy/taxonomy.module
@@ -527,7 +527,7 @@
       $connection = \Drupal::database();
       foreach ($tid_all as $tid) {
         $connection->merge('taxonomy_index')
-          ->key(['nid' => $node->id(), 'tid' => $tid, 'status' => $node->isPublished()])
+          ->key(['nid' => $node->id(), 'tid' => $tid, 'status' => $status])
           ->fields(['sticky' => $sticky, 'created' => $node->getCreatedTime()])
           ->execute();
       }
@@ -552,7 +552,7 @@
     if (!empty($tid_all)) {
       foreach ($tid_all as $tid) {
         db_merge('taxonomy_index')
-          ->key(['nid' => $node->id(), 'tid' => $tid, 'status' => $status])
+          ->key(['nid' => $node->id(), 'tid' => $tid, 'status' => $node->isPublished()])
           ->fields(['sticky' => $sticky, 'created' => $node->getCreatedTime()])
           ->execute();
       }
