MediaWiki REL1_39
storageTypeStats.php
Go to the documentation of this file.
1<?php
22require_once __DIR__ . '/../Maintenance.php';
23
25 public function execute() {
26 $dbr = $this->getDB( DB_REPLICA );
27
28 $endId = $dbr->selectField( 'text', 'MAX(old_id)', '', __METHOD__ );
29 if ( !$endId ) {
30 $this->fatalError( 'No text rows!' );
31 }
32
33 $binSize = intval( 10 ** ( floor( log10( $endId ) ) - 3 ) );
34 if ( $binSize < 100 ) {
35 $binSize = 100;
36 }
37 echo "Using bin size of $binSize\n";
38
39 $stats = [];
40
41 $classSql = <<<SQL
42 IF(old_flags LIKE '%external%',
43 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9a-f]{32}$',
44 'CGZ pointer',
45 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9]{1,6}$',
46 'DHB pointer',
47 IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+$',
48 'simple pointer',
49 'UNKNOWN pointer'
50 )
51 )
52 ),
53 IF(old_flags LIKE '%object%',
54 TRIM('"' FROM SUBSTRING_INDEX(SUBSTRING_INDEX(old_text, ':', 3), ':', -1)),
55 '[none]'
56 )
57 )
58SQL;
59
60 for ( $rangeStart = 0; $rangeStart < $endId; $rangeStart += $binSize ) {
61 if ( $rangeStart / $binSize % 10 == 0 ) {
62 echo "$rangeStart\r";
63 }
64 $res = $dbr->select(
65 'text',
66 [
67 'old_flags',
68 'class' => $classSql,
69 'count' => 'COUNT(*)',
70 ],
71 [
72 'old_id >= ' . intval( $rangeStart ),
73 'old_id < ' . intval( $rangeStart + $binSize )
74 ],
75 __METHOD__,
76 [ 'GROUP BY' => [ 'old_flags', 'class' ] ]
77 );
78
79 foreach ( $res as $row ) {
80 $flags = $row->old_flags;
81 if ( $flags === '' ) {
82 $flags = '[none]';
83 }
84 $class = $row->class;
85 $count = $row->count;
86 // @phan-suppress-next-line PhanImpossibleConditionInLoop,PhanPossiblyUndeclaredVariable False positive
87 if ( !isset( $stats[$flags][$class] ) ) {
88 $stats[$flags][$class] = [
89 'count' => 0,
90 'first' => $rangeStart,
91 'last' => 0
92 ];
93 }
94 $entry =& $stats[$flags][$class];
95 $entry['count'] += $count;
96 $entry['last'] = max( $entry['last'], $rangeStart + $binSize );
97 unset( $entry );
98 }
99 }
100 echo "\n\n";
101
102 $format = "%-29s %-39s %-19s %-29s\n";
103 printf( $format, "Flags", "Class", "Count", "old_id range" );
104 echo str_repeat( '-', 120 ) . "\n";
105 foreach ( $stats as $flags => $flagStats ) {
106 foreach ( $flagStats as $class => $entry ) {
107 printf( $format, $flags, $class, $entry['count'],
108 sprintf( "%-13d - %-13d", $entry['first'], $entry['last'] ) );
109 }
110 }
111 }
112}
113
114$maintClass = StorageTypeStats::class;
115require_once RUN_MAINTENANCE_IF_MAIN;
getDB()
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
execute()
Do the actual work.
const DB_REPLICA
Definition defines.php:26