concept: cursor - davidkhala/database GitHub Wiki

a database cursor is a mechanism that enables traversal over the records in a query result

  • 多用于存储过程,性能优化
  • akin to the programming language concept of iterator
  • 化批为流: cursor用于对结果集(批形态)进行流处理
    • 性能优化:save you memory, less lock for concurrent reads and writes on other rows
    • 性能劣化:重复的网络协商成本,更低的全量压缩比,更低的consistency level

和查询结果集对比

a SQL result is like a bag, you get to hold a whole bunch of rows at once, but not any of them individually. e.g.

  • downloading an video in one swoop

a SQL cursor is like a pair of tweezers (picker). With it, you can reach into the bag and grab a row, and then move onto the next.

  • video streaming