| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
require_once __DIR__ . '/../Maintenance.php'; |
| 24 |
|
| 25 |
|
| 26 |
class StorageTypeStats extends Maintenance { |
| 27 |
public function execute() { |
| 28 |
$dbr = $this->getReplicaDB(); |
| 29 |
|
| 30 |
$endId = $dbr->newSelectQueryBuilder() |
| 31 |
->select( 'MAX(old_id)' ) |
| 32 |
->from( 'text' ) |
| 33 |
->caller( __METHOD__ )->fetchField(); |
| 34 |
if ( !$endId ) { |
| 35 |
$this->fatalError( 'No text rows!' ); |
| 36 |
} |
| 37 |
|
| 38 |
$binSize = intval( 10 ** ( floor( log10( $endId ) ) - 3 ) ); |
| 39 |
if ( $binSize < 100 ) { |
| 40 |
$binSize = 100; |
| 41 |
} |
| 42 |
echo "Using bin size of $binSize\n"; |
| 43 |
|
| 44 |
$stats = []; |
| 45 |
|
| 46 |
$classSql = <<<SQL |
| 47 |
IF(old_flags LIKE '%external%', |
| 48 |
IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9a-f]{32}$', |
| 49 |
'CGZ pointer', |
| 50 |
IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+/[0-9]{1,6}$', |
| 51 |
'DHB pointer', |
| 52 |
IF(old_text REGEXP '^DB://[[:alnum:]]+/[0-9]+$', |
| 53 |
'simple pointer', |
| 54 |
'UNKNOWN pointer' |
| 55 |
) |
| 56 |
) |
| 57 |
), |
| 58 |
IF(old_flags LIKE '%object%', |
| 59 |
TRIM('"' FROM SUBSTRING_INDEX(SUBSTRING_INDEX(old_text, ':', 3), ':', -1)), |
| 60 |
'[none]' |
| 61 |
) |
| 62 |
) |
| 63 |
SQL; |
| 64 |
|
| 65 |
for ( $rangeStart = 0; $rangeStart < $endId; $rangeStart += $binSize ) { |
| 66 |
if ( $rangeStart / $binSize % 10 == 0 ) { |
| 67 |
echo "$rangeStart\r"; |
| 68 |
} |
| 69 |
$res = $dbr->newSelectQueryBuilder() |
| 70 |
->select( [ 'old_flags', 'class' => $classSql, 'count' => 'COUNT(*)' ] ) |
| 71 |
->from( 'text' ) |
| 72 |
->where( $dbr->expr( 'old_id', '>=', intval( $rangeStart ) ) ) |
| 73 |
->andWhere( $dbr->expr( 'old_id', '<', intval( $rangeStart + $binSize ) ) ) |
| 74 |
->groupBy( [ 'old_flags', 'class' ] ) |
| 75 |
->caller( __METHOD__ )->fetchResultSet(); |
| 76 |
|
| 77 |
foreach ( $res as $row ) { |
| 78 |
$flags = $row->old_flags; |
| 79 |
if ( $flags === '' ) { |
| 80 |
$flags = '[none]'; |
| 81 |
} |
| 82 |
$class = $row->class; |
| 83 |
$count = $row->count; |
| 84 |
|
| 85 |
if ( !isset( $stats[$flags][$class] ) ) { |
| 86 |
$stats[$flags][$class] = [ |
| 87 |
'count' => 0, |
| 88 |
'first' => $rangeStart, |
| 89 |
'last' => 0 |
| 90 |
]; |
| 91 |
} |
| 92 |
$entry =& $stats[$flags][$class]; |
| 93 |
$entry['count'] += $count; |
| 94 |
$entry['last'] = max( $entry['last'], $rangeStart + $binSize ); |
| 95 |
unset( $entry ); |
| 96 |
} |
| 97 |
} |
| 98 |
echo "\n\n"; |
| 99 |
|
| 100 |
$format = "%-29s %-39s %-19s %-29s\n"; |
| 101 |
printf( $format, "Flags", "Class", "Count", "old_id range" ); |
| 102 |
echo str_repeat( '-', 120 ) . "\n"; |
| 103 |
foreach ( $stats as $flags => $flagStats ) { |
| 104 |
foreach ( $flagStats as $class => $entry ) { |
| 105 |
printf( $format, $flags, $class, $entry['count'], |
| 106 |
sprintf( "%-13d - %-13d", $entry['first'], $entry['last'] ) ); |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
$maintClass = StorageTypeStats::class; |
| 114 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 115 |
|