summaryrefslogtreecommitdiff
path: root/plan_view.go
diff options
context:
space:
mode:
Diffstat (limited to 'plan_view.go')
-rw-r--r--plan_view.go32
1 files changed, 26 insertions, 6 deletions
diff --git a/plan_view.go b/plan_view.go
index 36b58c1..f2badfa 100644
--- a/plan_view.go
+++ b/plan_view.go
@@ -79,8 +79,29 @@ func (p *planView) SetPlan(as []*postgres.Explain) {
}
func buildNode(p *postgres.Plan) *tview.TreeNode {
- dur := f2d(p.ActualTotalTime)
- n := tview.NewTreeNode(fmt.Sprintf("%s (%s)", p.NodeType, dur.String()))
+ dur := p.EffectiveTotalTime()
+ var (
+ badEstimate string
+ sortBy string
+ scanOn string
+ scanIndex string
+ )
+ if p.IsBadEstimate() {
+ badEstimate = " [red](bad estimate)[white]"
+ }
+ if len(p.SortKey) > 0 {
+ sortBy = " by " + strings.Join(p.SortKey, ", ")
+ }
+ if p.RelationName != nil {
+ scanOn = " on " + *p.RelationName
+ }
+ if p.IndexName != nil {
+ scanIndex = " using " + *p.IndexName
+ }
+
+ label := fmt.Sprintf("%s (%s)%s%s%s%s", p.NodeType, dur.String(),
+ badEstimate, sortBy, scanOn, scanIndex)
+ n := tview.NewTreeNode(label)
n.SetSelectable(true)
n.SetReference(p)
for _, subplan := range p.Plans {
@@ -287,8 +308,7 @@ func f2a(f float32) string {
}
func f2d(f float32) time.Duration {
- return time.Duration(int(f)) * time.Millisecond
- // ms := time.Duration(int(f)) * time.Millisecond
- // ns := time.Duration(int((f-float32(ms))*1000)) * time.Nanosecond
- // return time.Duration(ms + ns)
+ // f is in milliseconds, multiply by 1k to get microseconds
+ // (thousandths of milliseconds)
+ return time.Duration(int(f)*1000) * time.Microsecond
}