MediaWiki REL1_39
benchmarkTruncate.php
Go to the documentation of this file.
1<?php
2
3require_once __DIR__ . '/../includes/Benchmarker.php';
4
11 public function execute() {
12 $fname = __METHOD__;
13 $dbw = $this->getDB( DB_PRIMARY );
14
15 $dbw->dropTable( 'benchmark_perm_test' );
16 $permTable = $dbw->tableName( 'benchmark_perm_test', 'unquoted' );
17 $dbw->duplicateTableStructure(
18 $dbw->tableName( 'page', 'unquoted' ),
19 $permTable,
20 false,
21 $fname
22 );
23
24 $dbw->dropTable( 'benchmark_temp_test' );
25 $tempTable = $dbw->tableName( 'benchmark_temp_test', 'unquoted' );
26 $dbw->duplicateTableStructure(
27 $dbw->tableName( 'page', 'unquoted' ),
28 $tempTable,
29 true,
30 $fname
31 );
32
33 $this->bench( [
34 'perm truncate' => static function () use ( $dbw, $fname, $permTable ) {
35 $dbw->query( "TRUNCATE $permTable", $fname );
36 },
37 'perm delete' => static function () use ( $dbw, $fname, $permTable ) {
38 $dbw->query( "DELETE FROM $permTable", $fname );
39 },
40 'temp truncate' => static function () use ( $dbw, $fname, $tempTable ) {
41 // Use a raw query not truncate() to avoid the "pristine" check.
42 // The other cases also use query() so that they will have comparable overhead.
43 $dbw->query( "TRUNCATE $tempTable", $fname );
44 },
45 'temp delete' => static function () use ( $dbw, $fname, $tempTable ) {
46 $dbw->query( "DELETE FROM $tempTable", $fname );
47 }
48 ] );
49
50 $dbw->dropTable( 'benchmark_perm_test', $fname );
51 $dbw->dropTable( 'benchmark_temp_test', $fname );
52 }
53}
54$maintClass = BenchmarkTruncate::class;
55require_once RUN_MAINTENANCE_IF_MAIN;
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