2

SQL novice here. In the Hello World section of the RMySQL github page, there is the following -

# You can fetch all results:
res <- dbSendQuery(con, "SELECT * FROM mtcars WHERE cyl = 4")
dbFetch(res)
dbClearResult(res)

I don't understand the purpose of dbClearResult(). This is important to me because I'm working with a few large tables and dbClearResult(rs) can be very slow at times (taking minutes to complete). However, if I go into the mysql shell I can simply kill a query instantaneously.

So, what is the purpose of dbClearResult() and is there any way to avoid it or speed it up?

Ben
  • 20,038
  • 30
  • 112
  • 189

1 Answers1

2

From the DBI documentation for dbClearResult:

Frees all resources (local and remote) associated with a result set. In some cases (e.g., very large result sets) this can be a critical step to avoid exhausting resources (memory, file descriptors, etc.)

Parfait
  • 104,375
  • 17
  • 94
  • 125
Clint
  • 973
  • 7
  • 18
  • 1
    I'm not voting down, but *only* pointing to documentation (without profounding further) is a very lousy answer, even more when the original question provides a better solution to its problem, albeit outside R. – Marcelo Ventura May 28 '20 at 19:53