Skip to content

Commit

Permalink
move timing as close as possible to query execution instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
xwb1989 committed Oct 20, 2015
1 parent 1d6b871 commit 054e149
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions interpreter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ func saveHistory() {
}

func executeLine(tx *sql.Tx, txnLine string) error {
start := time.Now()
if tidb.IsQuery(txnLine) {
start := time.Now()
rows, err := tx.Query(txnLine)
elapsed := time.Since(start).Seconds()
if err != nil {
return errors.Trace(err)
}
Expand Down Expand Up @@ -97,7 +98,6 @@ func executeLine(tx *sql.Tx, txnLine string) error {
result, _ := printer.GetPrintResult(cols, datas)
fmt.Printf("%s", result)

// report elapsed time and rows in set
switch len(datas) {
case 0:
fmt.Printf("Empty set")
Expand All @@ -106,13 +106,15 @@ func executeLine(tx *sql.Tx, txnLine string) error {
default:
fmt.Printf("%v rows in set", len(datas))
}

fmt.Printf(" (%.2f sec)\n", elapsed)
if err := rows.Err(); err != nil {
return errors.Trace(err)
}
} else {
// TODO: rows affected and last insert id
// TODO: last insert id
start := time.Now()
res, err := tx.Exec(txnLine)
elapsed := time.Since(start).Seconds()
if err != nil {
return errors.Trace(err)
}
Expand All @@ -128,8 +130,8 @@ func executeLine(tx *sql.Tx, txnLine string) error {
default:
fmt.Printf("Query OK, %v rows affected", cnt)
}
fmt.Printf(" (%.2f sec)\n", elapsed)
}
fmt.Printf(" (%.2f sec)\n", time.Since(start).Seconds())
return nil
}

Expand Down

0 comments on commit 054e149

Please sign in to comment.