diff --git a/pkg/sql/sqlstats/ssmemstorage/ss_mem_storage.go b/pkg/sql/sqlstats/ssmemstorage/ss_mem_storage.go index 47728138f51a..700f79259c56 100644 --- a/pkg/sql/sqlstats/ssmemstorage/ss_mem_storage.go +++ b/pkg/sql/sqlstats/ssmemstorage/ss_mem_storage.go @@ -400,7 +400,7 @@ type stmtStats struct { } } -func (s *stmtStats) sizeUnsafe() int64 { +func (s *stmtStats) sizeUnsafeLocked() int64 { const stmtStatsShallowSize = int64(unsafe.Sizeof(stmtStats{})) databaseNameSize := int64(len(s.mu.database)) @@ -832,7 +832,7 @@ func (s *Container) Add(ctx context.Context, other *Container) (err error) { // If we created a new entry for the fingerprint, we check if we have // exceeded our memory budget. if created { - estimatedAllocBytes := stats.sizeUnsafe() + k.size() + 8 /* stmtKey hash */ + estimatedAllocBytes := stats.sizeUnsafeLocked() + k.size() + 8 /* stmtKey hash */ // We still want to continue this loop to merge stats that are already // present in our map that do not require allocation. if latestErr := func() error { diff --git a/pkg/sql/sqlstats/ssmemstorage/ss_mem_writer.go b/pkg/sql/sqlstats/ssmemstorage/ss_mem_writer.go index 440571c647f7..b1fdbe6d2cee 100644 --- a/pkg/sql/sqlstats/ssmemstorage/ss_mem_writer.go +++ b/pkg/sql/sqlstats/ssmemstorage/ss_mem_writer.go @@ -173,7 +173,7 @@ func (s *Container) RecordStatement( if created { // stats size + stmtKey size + hash of the statementKey - estimatedMemoryAllocBytes := stats.sizeUnsafe() + statementKey.size() + 8 + estimatedMemoryAllocBytes := stats.sizeUnsafeLocked() + statementKey.size() + 8 // We also account for the memory used for s.sampledPlanMetadataCache. // timestamp size + key size + hash.