gorose icon indicating copy to clipboard operation
gorose copied to clipboard

提供 IfEnableSqlLog() 功能

Open greensea opened this issue 4 years ago • 0 comments

我在调用 Session.Execute() 方法的时候,发现这个方法内会使用 fmt.Sprint() 来格式化当前的查询语句,并保存到 lastSql 变量中。

然而,我的程序需要大量调用 Execute 方法,这时候会频繁调用 fmt.Sprint(),这浪费了一定的性能,根据 profile 的结果,Execute 中的 fmt.Sprint() 大约吃掉了 20% 的 CPU 时间。而实际上,我并不关心 LastSql,也不会去调用 LastSql() 方法,记录 lastSql 对我来说是没用的,但却消耗了客观的 CPU 时间。

我发现 Session.Execute() 中有一段被注释的代码,这段被注释的代码中有一个 IfEnableSqlLog() 的开关,但是现在的代码中并没有这个配置项,看起来这个配置项是被删除了?

希望重新提供 IfEnableSqlLog() 的功能,以便按需关闭记录 lastSql 的功能,避免 fmt.Sprint() 的无用开销。

greensea avatar Jun 25 '21 06:06 greensea