Skip to content

Commit

Permalink
add explanation for cache hit and if action is needed
Browse files Browse the repository at this point in the history
  • Loading branch information
encima committed Apr 10, 2024
1 parent ba690a4 commit c3c4312
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions internal/inspect/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,19 @@ func Run(ctx context.Context, config pgconn.Config, fsys afero.Fs, options ...fu
return err
}
// TODO: implement a markdown table marshaller
table := "|Name|Ratio|\n|-|-|\n"
table := "|Name|Ratio|OK?|Explanation|\n|-|-|-|-|\n"
for _, r := range result {
table += fmt.Sprintf("|`%s`|`%.6f`|\n", r.Name, r.Ratio)

ok := "Yup!"
if r.Ratio < 0.94 {
ok = "Maybe not..."
}
var explanation string
if r.Name == "index hit rate" {
explanation = "This is the ratio of index hits to index scans. If this ratio is low, it means that the database is not using indexes effectively. Check the `index-usage` command for more info."
} else if r.Name == "table hit rate" {
explanation = "This is the ratio of table hits to table scans. If this ratio is low, it means that your queries are not finding the data effectively. Check your query performance and it might be worth increasing your compute."
}
table += fmt.Sprintf("|`%s`|`%.6f`|`%s`|`%s`|\n", r.Name, r.Ratio, ok, explanation)
}
return list.RenderTable(table)
}

0 comments on commit c3c4312

Please sign in to comment.