database/sql: statements created with conn.PrepareContext are re-prepared in transactions #28130
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
I am trying to write a sql client that prepares some statements and then uses them in transactions. I am observing that
Tx.StmtContext
re-prepares each statement every time (defeating the purpose of using prepared statements, at least from a performance standpoint).This is another incarnation of #15606. The fix for that issue addresses the case where we create the statement via
DB.PrepareContext
. However, I am usingConn.PrepareContext
. I am then running transactions on the sameConn
, which triggers the code path below becausestmt.cg
is not nil:Note that (as an alternative) using
Db.PrepareContext
once for the application is problematic for other reasons - we have multiple parallel workers and they contend on some internal mutexes inRows
objects. Perhaps I should useDb.PrepareContext
once per each worker, even though I already have a specificConn
for each one?I am using go 1.11.
CC @adams-sarah @kardianos @johto
The text was updated successfully, but these errors were encountered: