How go-mysql-driver get data? "get all data at a time" or "only get a batch when we call rows.Next"?

42 views
Skip to first unread message

杜沁园

unread,
Jun 26, 2019, 8:59:00 AM6/26/19
to golang-nuts
When we operate with mysql with Go, as follow:


rows, err := db.Query(....)

for rows.Next() {
    .....
}


When the driver get data? 

Get all data at once when we call `Query`???

Or only get a batch of Data when we call `Next`, and get next batch of data when we run out of it????

Henrik Johansson

unread,
Jun 26, 2019, 9:19:48 AM6/26/19
to 杜沁园, golang-nuts
I am pretty sure it's the latter case with lazy loading when needed during the Next() call.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/f55712f4-a29e-42b8-84cf-0b39b1d0b32f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sa51...@mail.ustc.edu.cn

unread,
Jun 26, 2019, 2:04:36 PM6/26/19
to Henrik Johansson, golang-nuts
Get all data in the first Next() call? or only get a batch?

At2019-06-26 21:19:07,Henrik Johanssondahan...@gmail.comwrote:

Marcin Romaszewicz

unread,
Jun 26, 2019, 2:07:59 PM6/26/19
to sa51...@mail.ustc.edu.cn, Henrik Johansson, golang-nuts
No, it doesn't get all the data in the Next() call, it streams it incrementally from the DB. I've used it to stream gigabytes before, and they certainly didn't get buffered in RAM.

Reply all
Reply to author
Forward
0 new messages