function Connection::nextIdDelete

Same name and namespace in other branches
  1. 9 core/modules/mysql/src/Driver/Database/mysql/Connection.php \Drupal\mysql\Driver\Database\mysql\Connection::nextIdDelete()
  2. 8.9.x core/lib/Drupal/Core/Database/Driver/mysql/Connection.php \Drupal\Core\Database\Driver\mysql\Connection::nextIdDelete()
1 call to Connection::nextIdDelete()
Connection::__destruct in core/modules/mysql/src/Driver/Database/mysql/Connection.php
Ensures that the client connection can be garbage collected.

File

core/modules/mysql/src/Driver/Database/mysql/Connection.php, line 364

Class

Connection
MySQL implementation of \Drupal\Core\Database\Connection.

Namespace

Drupal\mysql\Driver\Database\mysql

Code

public function nextIdDelete() {
  @trigger_error(__METHOD__ . '() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Modules should use instead the keyvalue storage for the last used id. See https://www.drupal.org/node/3349345', E_USER_DEPRECATED);
  // While we want to clean up the table to keep it up from occupying too
  // much storage and memory, we must keep the highest value in the table
  // because InnoDB uses an in-memory auto-increment counter as long as the
  // server runs. When the server is stopped and restarted, InnoDB
  // re-initializes the counter for each table for the first INSERT to the
  // table based solely on values from the table so deleting all values would
  // be a problem in this case. Also, TRUNCATE resets the auto increment
  // counter.
  try {
    $max_id = $this->query('SELECT MAX(value) FROM {sequences}')
      ->fetchField();
    // We know we are using MySQL here, no need for the slower ::delete().
    $this->query('DELETE FROM {sequences} WHERE value < :value', [
      ':value' => $max_id,
    ]);
  } catch (DatabaseException $e) {
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.