MediaWiki master
benchmarkTruncate.php
Go to the documentation of this file.
1<?php
2
4
5// @codeCoverageIgnoreStart
6require_once __DIR__ . '/../includes/Benchmarker.php';
7// @codeCoverageIgnoreEnd
8
15 public function execute() {
16 $fname = __METHOD__;
17 $dbw = $this->getDB( DB_PRIMARY );
18
19 $dbw->dropTable( 'benchmark_perm_test', $fname );
20 $permTable = $dbw->tableName( 'benchmark_perm_test', 'raw' );
21 $dbw->duplicateTableStructure(
22 $dbw->tableName( 'page', 'raw' ),
23 $permTable,
24 false,
25 $fname
26 );
27
28 $dbw->dropTable( 'benchmark_temp_test', $fname );
29 $tempTable = $dbw->tableName( 'benchmark_temp_test', 'raw' );
30 $dbw->duplicateTableStructure(
31 $dbw->tableName( 'page', 'raw' ),
32 $tempTable,
33 true,
34 $fname
35 );
36
37 $this->bench( [
38 'perm truncate' => static function () use ( $dbw, $fname, $permTable ) {
39 $dbw->query( "TRUNCATE $permTable", $fname );
40 },
41 'perm delete' => static function () use ( $dbw, $fname, $permTable ) {
42 $dbw->query( "DELETE FROM $permTable", $fname );
43 },
44 'temp truncate' => static function () use ( $dbw, $fname, $tempTable ) {
45 // Use a raw query not truncate() to avoid the "pristine" check.
46 // The other cases also use query() so that they will have comparable overhead.
47 $dbw->query( "TRUNCATE $tempTable", $fname );
48 },
49 'temp delete' => static function () use ( $dbw, $fname, $tempTable ) {
50 $dbw->query( "DELETE FROM $tempTable", $fname );
51 }
52 ] );
53
54 $dbw->dropTable( 'benchmark_perm_test', $fname );
55 $dbw->dropTable( 'benchmark_temp_test', $fname );
56 }
57}
58// @codeCoverageIgnoreStart
59$maintClass = BenchmarkTruncate::class;
60require_once RUN_MAINTENANCE_IF_MAIN;
61// @codeCoverageIgnoreEnd
Maintenance script that benchmarks TRUNCATE versus DELETE queries.
execute()
Do the actual work.
Base class for benchmark scripts.
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
const DB_PRIMARY
Definition defines.php:28