MediaWiki
REL1_31
bench_delete_truncate.php
Go to the documentation of this file.
1
<?php
24
require_once __DIR__ .
'/Benchmarker.php'
;
25
26
use
Wikimedia\Rdbms\IDatabase
;
27
use
Wikimedia\Rdbms\IMaintainableDatabase
;
28
34
class
BenchmarkDeleteTruncate
extends
Benchmarker
{
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::class;
105
require_once
RUN_MAINTENANCE_IF_MAIN
;
$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
BenchmarkDeleteTruncate\__construct
__construct()
Default constructor.
Definition
bench_delete_truncate.php:37
BenchmarkDeleteTruncate\truncate
truncate( $dbw)
Definition
bench_delete_truncate.php:98
BenchmarkDeleteTruncate\$defaultCount
$defaultCount
Definition
bench_delete_truncate.php:35
BenchmarkDeleteTruncate\execute
execute()
Do the actual work.
Definition
bench_delete_truncate.php:42
Benchmarker
Base class for benchmark scripts.
Definition
Benchmarker.php:40
Benchmarker\bench
bench(array $benchs)
Definition
Benchmarker.php:50
Maintenance\getDB
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
Definition
Maintenance.php:1309
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:291
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition
IDatabase.php:38
Wikimedia\Rdbms\IMaintainableDatabase
Advanced database interface for IDatabase handles that include maintenance methods.
Definition
IMaintainableDatabase.php:38
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition
maintenance.txt:50
DB_MASTER
const DB_MASTER
Definition
defines.php:29
maintenance
benchmarks
bench_delete_truncate.php
Generated on Mon Nov 25 2024 15:35:56 for MediaWiki by
1.10.0