From 9349774454232ae0017982fe16459ae60528353a Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Wed, 27 Nov 2024 13:45:05 +0100 Subject: [PATCH] feat: better report for txs Signed-off-by: Andres Taylor --- go/summarize/markdown.go | 8 ++++++++ go/summarize/summarize-transactions.go | 28 +++++++++++++++++--------- go/summarize/summary.go | 4 ++++ 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/go/summarize/markdown.go b/go/summarize/markdown.go index 94b80fe..3af98fd 100644 --- a/go/summarize/markdown.go +++ b/go/summarize/markdown.go @@ -242,6 +242,14 @@ func renderTransactions(md *markdown.MarkDown, transactions []TransactionSummary md.Printf("%d. **%s** on `%s` \n", i+1, strings.ToTitle(query.Type), query.Table) md.Printf(" Predicates: %s\n\n", strings.Join(query.Predicates, " AND ")) } + + md.PrintHeader("Shared Predicate Values", 3) + for idx, join := range tx.Joins { + md.Printf("* Value %d applied to:\n", idx) + for _, s := range join { + md.Printf(" - %s\n", s) + } + } if i != len(transactions)-1 { md.Printf("---\n") } diff --git a/go/summarize/summarize-transactions.go b/go/summarize/summarize-transactions.go index 6e16f6c..809bc45 100644 --- a/go/summarize/summarize-transactions.go +++ b/go/summarize/summarize-transactions.go @@ -17,6 +17,10 @@ limitations under the License. package summarize import ( + "fmt" + "maps" + "slices" + "vitess.io/vitess/go/slice" "github.com/vitessio/vt/go/transactions" @@ -24,26 +28,25 @@ import ( func summarizeTransactions(s *Summary, txs []transactions.Signature) error { for _, tx := range txs { - patterns, interesting := summarizeQueries(tx.Queries) - if !interesting { + patterns, joins := summarizeQueries(tx.Queries) + if len(joins) == 0 { continue } s.transactions = append(s.transactions, TransactionSummary{ Count: tx.Count, Queries: patterns, + Joins: joins, }) } return nil } -func summarizeQueries(queries []transactions.Query) (patterns []QueryPattern, interesting bool) { +func summarizeQueries(queries []transactions.Query) (patterns []QueryPattern, joins [][]string) { + columnJoins := map[int][]string{} for _, q := range queries { - if !interesting { - // Check if any of the predicates are interesting - for _, predicate := range q.Predicates { - if predicate.Val >= 0 { - interesting = true - } + for _, predicate := range q.Predicates { + if predicate.Val >= 0 { + columnJoins[predicate.Val] = append(columnJoins[predicate.Val], fmt.Sprintf("%s.%s", q.AffectedTable, predicate.Col)) } } patterns = append(patterns, QueryPattern{ @@ -53,5 +56,12 @@ func summarizeQueries(queries []transactions.Query) (patterns []QueryPattern, in UpdatedColumns: q.UpdatedColumns, }) } + joinKeys := slices.Collect(maps.Keys(columnJoins)) + slices.Sort(joinKeys) + + for _, key := range joinKeys { + cols := columnJoins[key] + joins = append(joins, cols) + } return } diff --git a/go/summarize/summary.go b/go/summarize/summary.go index 8c438bd..7cf2d0e 100644 --- a/go/summarize/summary.go +++ b/go/summarize/summary.go @@ -52,6 +52,10 @@ type ( TransactionSummary struct { Count int Queries []QueryPattern + + // Joins contain a list of columns that are joined together. + // Each outer slice is one set of columns that are joined together. + Joins [][]string } QueryPattern struct {