From c3c43129ad94c28a62d27336689c5db198a5dad4 Mon Sep 17 00:00:00 2001 From: Chris Gwilliams <517923+encima@users.noreply.github.com> Date: Wed, 10 Apr 2024 14:19:23 +0300 Subject: [PATCH] add explanation for cache hit and if action is needed --- internal/inspect/cache/cache.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/internal/inspect/cache/cache.go b/internal/inspect/cache/cache.go index 10c552d18..eb16a7bb4 100644 --- a/internal/inspect/cache/cache.go +++ b/internal/inspect/cache/cache.go @@ -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) }