英文:
Is there any significant performance difference between Query and QueryRow in the sql package?
问题
在"database/sql"
包中,即使在查询的末尾加上LIMIT 1;
,func (db *DB) Query
和func (db *DB) QueryRow
之间是否有显著的性能差异?
英文:
Is there any significant performance difference between the
func (db *DB) Query(query string, args ...interface{}) (*Rows, error)
and the
func (db *DB) QueryRow(query string, args ...interface{}) *Row
in the "database/sql"
package even if you have LIMIT 1;
at the end of your query?
答案1
得分: 3
区别在于函数调用的开销(与向数据库发送查询相比几乎没有)。QueryRow调用Query,然后将结果封装在sql.Row中。
英文:
The difference is the overhead of a function call (i.e., almost nothing, compared to sending a query to your database). QueryRow calls Query, and then wraps the results in an sql.Row.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论