diff --git a/docs/generated/http/full.md b/docs/generated/http/full.md index 95c2a0076530..d781ce81bc68 100644 --- a/docs/generated/http/full.md +++ b/docs/generated/http/full.md @@ -5206,6 +5206,9 @@ a table. | configure_zone_statement | [string](#cockroach.server.serverpb.TableDetailsResponse-string) | | configure_zone_statement is the output of "SHOW ZONE CONFIGURATION FOR TABLE" for this table. It is a SQL statement that would re-configure the table's current zone if executed. | [reserved](#support-status) | | stats_last_created_at | [google.protobuf.Timestamp](#cockroach.server.serverpb.TableDetailsResponse-google.protobuf.Timestamp) | | stats_last_created_at is the time at which statistics were last created. | [reserved](#support-status) | | has_index_recommendations | [bool](#cockroach.server.serverpb.TableDetailsResponse-bool) | | has_index_recommendations notifies if the there are index recommendations on this table. | [reserved](#support-status) | +| data_total_bytes | [int64](#cockroach.server.serverpb.TableDetailsResponse-int64) | | data_total_bytes is the size in bytes of live and non-live data on the table. | [reserved](#support-status) | +| data_non_live_bytes | [int64](#cockroach.server.serverpb.TableDetailsResponse-int64) | | data_non_live_bytes is the size in bytes of non-live (MVCC) data on the table. | [reserved](#support-status) | +| data_non_live_percentage | [float](#cockroach.server.serverpb.TableDetailsResponse-float) | | garbage_percentage is the percentage of non-live (MVCC) data on the table. | [reserved](#support-status) | diff --git a/docs/generated/swagger/spec.json b/docs/generated/swagger/spec.json index 359df0eac437..5cb949a6a2af 100644 --- a/docs/generated/swagger/spec.json +++ b/docs/generated/swagger/spec.json @@ -1523,6 +1523,24 @@ "type": "string", "x-go-name": "CreateTableStatement" }, + "data_non_live_bytes": { + "description": "data_non_live_bytes is the size in bytes of non-live (MVCC) data on the table.", + "type": "integer", + "format": "int64", + "x-go-name": "DataNonLiveBytes" + }, + "data_non_live_percentage": { + "description": "garbage_percentage is the percentage of non-live (MVCC) data on the table.", + "type": "number", + "format": "float", + "x-go-name": "DataNonLivePercentage" + }, + "data_total_bytes": { + "description": "data_total_bytes is the size in bytes of live and non-live data on the table.", + "type": "integer", + "format": "int64", + "x-go-name": "DataTotalBytes" + }, "descriptor_id": { "description": "descriptor_id is an identifier used to uniquely identify this table.\nIt can be used to find events pertaining to this table by filtering on\nthe 'target_id' field of events.", "type": "integer", diff --git a/pkg/server/admin.go b/pkg/server/admin.go index 5af4dfe14cb3..ca8c8aa412d1 100644 --- a/pkg/server/admin.go +++ b/pkg/server/admin.go @@ -897,6 +897,57 @@ func (s *adminServer) tableDetailsHelper( resp.CreateTableStatement = createStmt } + // MVCC Garbage result. + row, cols, err = s.server.sqlServer.internalExecutor.QueryRowExWithCols( + ctx, "admin-show-mvcc-garbage-pct", nil, + sessiondata.InternalExecutorOverride{User: userName}, + `WITH + range_stats AS ( + SELECT + crdb_internal.range_stats(start_key) AS d + FROM + crdb_internal.ranges_no_leases + WHERE + table_id = $1::REGCLASS + ), + aggregated AS ( + SELECT + sum((d->>'live_bytes')::INT8) AS live, + sum((d->>'key_bytes')::INT8 + (d->>'val_bytes')::INT8) AS total + FROM + range_stats + ) + SELECT + total::INT8, + (total - live)::INT8 as garbage_bytes, + COALESCE((total - live) / NULLIF(total,0), 0)::FLOAT as garbage_percentage + FROM aggregated`, + escQualTable, + ) + if err != nil { + return nil, err + } + if row != nil { + scanner := makeResultScanner(cols) + var totalBytes int64 + if err := scanner.Scan(row, "total", &totalBytes); err != nil { + return nil, err + } + resp.DataTotalBytes = totalBytes + + var garbageBytes int64 + if err := scanner.Scan(row, "garbage_bytes", &garbageBytes); err != nil { + return nil, err + } + resp.DataNonLiveBytes = garbageBytes + + var garbagePct float32 + if err := scanner.Scan(row, "garbage_percentage", &garbagePct); err != nil { + return nil, err + } + resp.DataNonLivePercentage = garbagePct + } + // Marshal SHOW STATISTICS result. row, cols, err = s.server.sqlServer.internalExecutor.QueryRowExWithCols( ctx, "admin-show-statistics", nil, /* txn */ diff --git a/pkg/server/serverpb/admin.proto b/pkg/server/serverpb/admin.proto index f3eda8801cfd..dc32a12f0b74 100644 --- a/pkg/server/serverpb/admin.proto +++ b/pkg/server/serverpb/admin.proto @@ -218,6 +218,12 @@ message TableDetailsResponse { // has_index_recommendations notifies if the there are index recommendations // on this table. bool has_index_recommendations = 11; + // data_total_bytes is the size in bytes of live and non-live data on the table. + int64 data_total_bytes = 12; + // data_non_live_bytes is the size in bytes of non-live (MVCC) data on the table. + int64 data_non_live_bytes = 13; + // garbage_percentage is the percentage of non-live (MVCC) data on the table. + float data_non_live_percentage = 14; } // TableStatsRequest is a request for detailed, computationally expensive