MediaWiki  1.30.0
bench_delete_truncate.php
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/Benchmarker.php';
25 
28 
35  protected $defaultCount = 10;
36 
37  public function __construct() {
38  parent::__construct();
39  $this->addDescription( 'Benchmarks SQL DELETE vs SQL TRUNCATE.' );
40  }
41 
42  public function execute() {
43  $dbw = $this->getDB( DB_MASTER );
44 
45  $test = $dbw->tableName( 'test' );
46  $dbw->query( "CREATE TABLE IF NOT EXISTS /*_*/$test (
47  test_id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
48  text varbinary(255) NOT NULL
49 );" );
50 
51  $this->bench( [
52  'Delete' => [
53  'setup' => function () use ( $dbw ) {
54  $this->insertData( $dbw );
55  },
56  'function' => function () use ( $dbw ) {
57  $this->delete( $dbw );
58  }
59  ],
60  'Truncate' => [
61  'setup' => function () use ( $dbw ) {
62  $this->insertData( $dbw );
63  },
64  'function' => function () use ( $dbw ) {
65  $this->truncate( $dbw );
66  }
67  ]
68  ] );
69 
70  $dbw->dropTable( 'test' );
71  }
72 
77  private function insertData( $dbw ) {
78  $range = range( 0, 1024 );
79  $data = [];
80  foreach ( $range as $r ) {
81  $data[] = [ 'text' => $r ];
82  }
83  $dbw->insert( 'test', $data, __METHOD__ );
84  }
85 
90  private function delete( $dbw ) {
91  $dbw->delete( 'text', '*', __METHOD__ );
92  }
93 
98  private function truncate( $dbw ) {
99  $test = $dbw->tableName( 'test' );
100  $dbw->query( "TRUNCATE TABLE $test" );
101  }
102 }
103 
104 $maintClass = 'BenchmarkDeleteTruncate';
105 require_once RUN_MAINTENANCE_IF_MAIN;
BenchmarkDeleteTruncate\truncate
truncate( $dbw)
Definition: bench_delete_truncate.php:98
BenchmarkDeleteTruncate\execute
execute()
Do the actual work.
Definition: bench_delete_truncate.php:42
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:287
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
Benchmarker\bench
bench(array $benchs)
Definition: Benchmarker.php:46
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:40
BenchmarkDeleteTruncate\__construct
__construct()
Default constructor.
Definition: bench_delete_truncate.php:37
DB_MASTER
const DB_MASTER
Definition: defines.php:26
Benchmarker
Base class for benchmark scripts.
Definition: Benchmarker.php:36
$maintClass
$maintClass
Definition: bench_delete_truncate.php:104
BenchmarkDeleteTruncate
Maintenance script that benchmarks SQL DELETE vs SQL TRUNCATE.
Definition: bench_delete_truncate.php:34
BenchmarkDeleteTruncate\insertData
insertData( $dbw)
Definition: bench_delete_truncate.php:77
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Maintenance\getDB
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1251
BenchmarkDeleteTruncate\$defaultCount
$defaultCount
Definition: bench_delete_truncate.php:35
Wikimedia\Rdbms\IMaintainableDatabase
Advanced database interface for IDatabase handles that include maintenance methods.
Definition: IMaintainableDatabase.php:39