mysql icon indicating copy to clipboard operation
mysql copied to clipboard

Implement cursor support

Open julienschmidt opened this issue 5 years ago • 3 comments

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.

julienschmidt avatar Jan 07 '20 12:01 julienschmidt

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.

advdv avatar Oct 04 '20 10:10 advdv

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).

methane avatar Oct 05 '20 02:10 methane

Thank you for the quick response, that's great to hear!

advdv avatar Oct 05 '20 07:10 advdv