Skip to content

Commit

Permalink
feat: better report for txs
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Nov 27, 2024
1 parent 902500e commit 9349774
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
8 changes: 8 additions & 0 deletions go/summarize/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
28 changes: 19 additions & 9 deletions go/summarize/summarize-transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,36 @@ limitations under the License.
package summarize

import (
"fmt"
"maps"
"slices"

"vitess.io/vitess/go/slice"

"github.com/vitessio/vt/go/transactions"
)

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{
Expand All @@ -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
}
4 changes: 4 additions & 0 deletions go/summarize/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9349774

Please sign in to comment.