V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
ahmcsxcc
V2EX  ›  Go 编程语言

golang sql 包的 next 方法是每次到数据库端取一条数据?

  •  
  •   ahmcsxcc · 2020-05-13 18:21:14 +08:00 · 1001 次点击
    这是一个创建于 1453 天前的主题,其中的信息可能已经有所发展或是发生改变。

    是这样吗?

    如果是这样这样网络开销是不是有点大?

    tms
        1
    tms  
       2020-05-14 02:05:24 +08:00
    准确说是 next 一次从 buffer 里取一条数据到 lastcols,至于你说的数据库和客户端的网络开销和交互取决于 buffer,是 driver 的事情,由 client 和 server 端配合来进行管理。
    sql 的 next 定义参考 https://golang.org/src/database/sql/sql.go?s=77737:77764#L2732
    对于 mysql 如 go-sql-driver 这个 driver 在 packets.go 里有 readRow 调用 readPacket 来管理 buffer.go 定义的 buffer 。
    对应 mysql server 端的 https://dev.mysql.com/doc/internals/en/com-query-response.html
    其他数据库 server 和 driver,也可以对应研究一下。
    ahmcsxcc
        2
    ahmcsxcc  
    OP
       2020-05-14 09:36:36 +08:00
    @tms #1
    感谢,我先去研究研究
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1009 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 18:13 · PVG 02:13 · LAX 11:13 · JFK 14:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.