Hi 大家好,我写了一个go mysql驱动的一个优化-stmt cache

sam6666666 · · 2968 次点击
你是不是对prepare有什么误解 正常操作是不需要prepare的 prepare出的stmt本来就是为了多次使用的啊。
#1
更多评论
考虑下多个协程操作数据库的场景,另外stmt是跟连接绑定的。
#2
文档先确认下啊…… https://golang.org/pkg/database/sql/#Stmt Stmt is a prepared statement. A Stmt is safe for concurrent use by multiple goroutines. If a Stmt is prepared on a Tx or Conn, it will be bound to a single underlying connection forever. If the Tx or Conn closes, the Stmt will become unusable and all operations will return an error. If a Stmt is prepared on a DB, it will remain usable for the lifetime of the DB. When the Stmt needs to execute on a new underlying connection, it will prepare itself on the new connection automatically.
#3