MediaWiki  master
storageTypeStats.php
Go to the documentation of this file.
1 <?php
22 require_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  )
58 SQL;
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  if ( !isset( $stats[$flags][$class] ) ) {
87  $stats[$flags][$class] = [
88  'count' => 0,
89  'first' => $rangeStart,
90  'last' => 0
91  ];
92  }
93  $entry =& $stats[$flags][$class];
94  $entry['count'] += $count;
95  $entry['last'] = max( $entry['last'], $rangeStart + $binSize );
96  unset( $entry );
97  }
98  }
99  echo "\n\n";
100 
101  $format = "%-29s %-39s %-19s %-29s\n";
102  printf( $format, "Flags", "Class", "Count", "old_id range" );
103  echo str_repeat( '-', 120 ) . "\n";
104  foreach ( $stats as $flags => $flagStats ) {
105  foreach ( $flagStats as $class => $entry ) {
106  printf( $format, $flags, $class, $entry['count'],
107  sprintf( "%-13d - %-13d", $entry['first'], $entry['last'] ) );
108  }
109  }
110  }
111 }
112 
113 $maintClass = StorageTypeStats::class;
114 require_once RUN_MAINTENANCE_IF_MAIN;
StorageTypeStats\execute
execute()
Do the actual work.
Definition: storageTypeStats.php:25
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:489
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:59
$res
$res
Definition: testCompression.php:57
$maintClass
$maintClass
Definition: storageTypeStats.php:113
$dbr
$dbr
Definition: testCompression.php:54
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
Maintenance\getDB
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1362
StorageTypeStats
Definition: storageTypeStats.php:24