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