function Truncate::execute

Same name in this branch
  1. main core/lib/Drupal/Core/Database/Query/Truncate.php \Drupal\Core\Database\Query\Truncate::execute()
Same name and namespace in other branches
  1. 11.x core/modules/pgsql/src/Driver/Database/pgsql/Truncate.php \Drupal\pgsql\Driver\Database\pgsql\Truncate::execute()
  2. 11.x core/lib/Drupal/Core/Database/Query/Truncate.php \Drupal\Core\Database\Query\Truncate::execute()
  3. 10 core/modules/pgsql/src/Driver/Database/pgsql/Truncate.php \Drupal\pgsql\Driver\Database\pgsql\Truncate::execute()
  4. 10 core/lib/Drupal/Core/Database/Query/Truncate.php \Drupal\Core\Database\Query\Truncate::execute()
  5. 9 core/modules/pgsql/src/Driver/Database/pgsql/Truncate.php \Drupal\pgsql\Driver\Database\pgsql\Truncate::execute()
  6. 9 core/lib/Drupal/Core/Database/Query/Truncate.php \Drupal\Core\Database\Query\Truncate::execute()
  7. 8.9.x core/lib/Drupal/Core/Database/Driver/pgsql/Truncate.php \Drupal\Core\Database\Driver\pgsql\Truncate::execute()
  8. 8.9.x core/lib/Drupal/Core/Database/Query/Truncate.php \Drupal\Core\Database\Query\Truncate::execute()

Executes the TRUNCATE query.

In most cases, TRUNCATE is not a transaction safe statement as it is a DDL statement which results in an implicit COMMIT. When we are in a transaction, fallback to the slower, but transactional, DELETE. PostgreSQL also locks the entire table for a TRUNCATE strongly reducing the concurrency with other transactions.

Overrides Truncate::execute

File

core/modules/pgsql/src/Driver/Database/pgsql/Truncate.php, line 15

Class

Truncate
PostgreSQL implementation of \Drupal\Core\Database\Query\Truncate.

Namespace

Drupal\pgsql\Driver\Database\pgsql

Code

public function execute() : void {
  if ($this->connection
    ->inTransaction()) {
    $savepoint = $this->connection
      ->startTransaction('mimic_implicit_commit');
  }
  try {
    parent::execute();
  } catch (\Exception $e) {
    if (isset($savepoint)) {
      $savepoint->rollback();
    }
    throw $e;
  }
  if (isset($savepoint)) {
    $savepoint->commitOrRelease();
  }
}

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