Skip to content

Commit 117b8b4

Browse files
committed
Show how long it too to do query from Go for
#1 debugging
1 parent 9f66154 commit 117b8b4

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

main.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"log"
99
"net/http"
1010
"os"
11+
"time"
1112

1213
_ "modernc.org/sqlite"
1314
)
@@ -62,7 +63,7 @@ func (server *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
6263
server.views.ExecuteTemplate(w, "index.html", nil)
6364
return
6465
}
65-
server.log.Println("Preforming query", query)
66+
start := time.Now()
6667
rows, err := server.db.Query("SELECT word FROM words where \"word\" LIKE ?", query+"%")
6768
if err != nil {
6869
http.Error(w, err.Error(), http.StatusInternalServerError)
@@ -82,6 +83,8 @@ func (server *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
8283
}
8384

8485
rows.Close()
86+
duration := time.Since(start)
87+
server.log.Printf("Performed query %q in %v", query, duration)
8588

8689
server.writeJSON(w, results)
8790
}

search.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# select word, length from words where "word" like "$1%"
22
sqlite3 words.sqlite <<HERE
3-
SELECT word FROM words where "word" like "wa%"
3+
EXPLAIN QUERY PLAN
4+
select word from words where "word" like "${1:-for}%"
45
HERE
56

67
# not using USING INDEX words_index_1 ... why?

0 commit comments

Comments
 (0)