@@ -319,6 +319,8 @@ func (d *DB) loadTableStats(
319
319
stats .NumDeletions = props .NumDeletions
320
320
stats .NumRangeKeySets = props .NumRangeKeySets
321
321
stats .ValueBlocksSize = props .ValueBlocksSize
322
+ stats .RawKeySize = props .RawKeySize
323
+ stats .RawValueSize = props .RawValueSize
322
324
stats .CompressionType = block .CompressionFromString (props .CompressionName )
323
325
if props .NumDataBlocks > 0 {
324
326
stats .TombstoneDenseBlocksRatio = float64 (props .NumTombstoneDenseBlocks ) / float64 (props .NumDataBlocks )
@@ -509,9 +511,15 @@ func (d *DB) estimateSizesBeneath(
509
511
510
512
for l := level + 1 ; l < numLevels ; l ++ {
511
513
for tableBeneath := range v .Overlaps (l , meta .UserKeyBounds ()).All () {
514
+ fileSum += tableBeneath .Size
515
+ if tableBeneath .StatsValid () {
516
+ entryCount += tableBeneath .Stats .NumEntries
517
+ keySum += tableBeneath .Stats .RawKeySize
518
+ valSum += tableBeneath .Stats .RawValueSize
519
+ continue
520
+ }
521
+ // If stats aren't available, we need to read the properties block.
512
522
err := d .fileCache .withReader (ctx , block .NoReadEnv , tableBeneath , func (v * sstable.Reader , _ sstable.ReadEnv ) (err error ) {
513
- // TODO(xinhaoz): We should avoid reading the properties block here.
514
- // See https://github.com/cockroachdb/pebble/issues/4792.
515
523
loadedProps , err := v .ReadPropertiesBlock (ctx , nil /* buffer pool */ )
516
524
if err != nil {
517
525
return err
@@ -521,8 +529,7 @@ func (d *DB) estimateSizesBeneath(
521
529
props = loadedProps .GetScaledProperties (tableBeneath .TableBacking .Size , tableBeneath .Size )
522
530
}
523
531
524
- fileSum += tableBeneath .Size
525
- entryCount += tableBeneath .Stats .NumEntries
532
+ entryCount += props .NumEntries
526
533
keySum += props .RawKeySize
527
534
valSum += props .RawValueSize
528
535
return nil
@@ -730,6 +737,8 @@ func maybeSetStatsFromProperties(
730
737
meta .Stats .PointDeletionsBytesEstimate = pointEstimate
731
738
meta .Stats .RangeDeletionsBytesEstimate = 0
732
739
meta .Stats .ValueBlocksSize = props .ValueBlocksSize
740
+ meta .Stats .RawKeySize = props .RawKeySize
741
+ meta .Stats .RawValueSize = props .RawValueSize
733
742
meta .Stats .CompressionType = block .CompressionFromString (props .CompressionName )
734
743
meta .StatsMarkValid ()
735
744
sanityCheckStats (meta , logger , "stats from properties" )
0 commit comments