mysql
mysql copied to clipboard
Implement cursor support
Issue description
In some cases it might be undesirable to fetch a potentially huge resultset at once.
MySQL provides cursors for that in the binary protocol (prepared statements).
First, a cursor flag has to be set in COM_STMT_EXECUTE
, then the result chunks can be requested with the COM_STMT_FETCH
command.
Initially, we will probably only support forward-only and read-only cursors. However the question remains, trough what interface we make this feature available.
First off, thank you for the work that is put into this project!
I'm evaluating database drivers an I'm wondering what the lack of cursors means for a potential application. Let's say I want to stream a large result set from the database to the client would it mean that I now need to store the full result in-memory (on the web server)? Does calling rows.Scan
read all results into memory or does it copy from the underlying connection in chucks or rows?
If not, would there be workaround for that usecase? I could keep a cursor on the web-server or at client and query the database repeatedly. But that might mean the read as a whole is spread across multiple transactions.
Let's say I want to stream a large result set from the database to the client would it mean that I now need to store the full result in-memory (on the web server)?
No.
Does calling
rows.Scan
read all results into memory or does it copy from the underlying connection in chucks or rows?
"copy from the underlying connection in chucks"
Not having cursor is not affect most users. That's why many user use this driver without problem.
With cursor, you can fetch two resultset simultaneously in one connection (transaction).
Thank you for the quick response, that's great to hear!