aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/database/sql/sql_test.go
diff options
context:
space:
mode:
authorMarko Tiikkaja <marko@joh.to>2014-09-02 09:08:41 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2014-09-02 09:08:41 -0700
commit90e2e2b89633770d42f2ff558588dfc53c3288c8 (patch)
treeab90f5457d66b6502af82d35461b5a131a84c988 /src/pkg/database/sql/sql_test.go
parent60447c2d951fbaf5fcd16a773d11905abae9478f (diff)
downloadgo-90e2e2b89633770d42f2ff558588dfc53c3288c8.tar.xz
database/sql: Avoid re-preparing statements when all connections are busy
Previously, if all connections were busy, we would always re-prepare the statement on the connection we were assigned from the pool. That meant that if all connections were busy most of the time, the number of prepared statements for each connection would keep increasing over time. Instead, after getting a free connection, check to see if the statement has already been prepared on it, and reuse the statement handle if so. LGTM=bradfitz R=golang-codereviews, gobot, bradfitz CC=golang-codereviews https://golang.org/cl/116930043
Diffstat (limited to 'src/pkg/database/sql/sql_test.go')
-rw-r--r--src/pkg/database/sql/sql_test.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/pkg/database/sql/sql_test.go b/src/pkg/database/sql/sql_test.go
index 8849c81c4b..12e5a6fd6f 100644
--- a/src/pkg/database/sql/sql_test.go
+++ b/src/pkg/database/sql/sql_test.go
@@ -1348,6 +1348,11 @@ func TestErrBadConnReconnect(t *testing.T) {
return nil
})
+ // Provide a way to force a re-prepare of a statement on next execution
+ forcePrepare := func(stmt *Stmt) {
+ stmt.css = nil
+ }
+
// stmt.Exec
stmt1, err := db.Prepare("INSERT|t1|name=?,age=?,dead=?")
if err != nil {
@@ -1355,9 +1360,7 @@ func TestErrBadConnReconnect(t *testing.T) {
}
defer stmt1.Close()
// make sure we must prepare the stmt first
- for _, cs := range stmt1.css {
- cs.dc.inUse = true
- }
+ forcePrepare(stmt1)
stmtExec := func() error {
_, err := stmt1.Exec("Gopher", 3, false)
@@ -1373,9 +1376,7 @@ func TestErrBadConnReconnect(t *testing.T) {
}
defer stmt2.Close()
// make sure we must prepare the stmt first
- for _, cs := range stmt2.css {
- cs.dc.inUse = true
- }
+ forcePrepare(stmt2)
stmtQuery := func() error {
rows, err := stmt2.Query()