-
Notifications
You must be signed in to change notification settings - Fork 18k
database/sql: No way to attach prepared statements to pooled connections #4921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Comments
> However, preparing a statement takes the database connection out of the pool. And puts it back in the pool. And once that prepared statement needs to run, it prefers the connection that has it prepared, if it's in the pool and free. If not, it prepares another one. The right amount should soon be prepared, no? Labels changed: added priority-later, removed priority-triage, go1.1maybe. Status changed to WaitingForReply. |
That makes sense. Looking at the code, it appears to me as though under highly concurrent loads it will re-prepare statements many times, because it only remembers the most recently prepared connection and can't remember that it has prepared the statement on other connections. Is this correct or am I misreading? |
I think (hope) you're misreading. (*Stmt).Exec calls (*Stmt).connStmt to get a valid conn with that statement prepared. connStmt iterates over all of its s.css (list of conn/stmt pairs), and tries to find a conn that's free. Only if none are free does it re-prepare a new one. I intend to do some cleanup in this area for another open bug, but I don't think it's fundamentally broken right now. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by daniel.r.heath:
The text was updated successfully, but these errors were encountered: