You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15Lines changed: 15 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -212,6 +212,21 @@ This is especially helpful since it saves the cost of creating the row in Ruby i
212
212
If you only plan on using each row once, then it's much more efficient to disable this behavior by setting the `:cache_rows` option to false.
213
213
This would be helpful if you wanted to iterate over the results in a streaming manner. Meaning the GC would cleanup rows you don't need anymore as you're iterating over the result set.
214
214
215
+
### Streaming
216
+
217
+
`Mysql2::Client` can optionally only fetch rows from the server on demand by setting `:stream => true`. This is handy when handling very large result sets which might not fit in memory on the client.
218
+
219
+
```ruby
220
+
result = client.query("SELECT * FROM really_big_Table", :stream => true)
221
+
```
222
+
223
+
There are a few things that need to be kept in mind while using streaming:
224
+
225
+
*`:cache_rows` is ignored currently. (if you want to use `:cache_rows` you probably don't want to be using `:stream`)
226
+
* You must fetch all rows in the result set of your query before you can make new queries. (i.e. with `Mysql2::Result#each`)
227
+
228
+
Read more about the consequences of using `mysql_use_result` (what streaming is implemented with) here: http://dev.mysql.com/doc/refman/5.0/en/mysql-use-result.html.
229
+
215
230
## ActiveRecord
216
231
217
232
To use the ActiveRecord driver (with or without rails), all you should need to do is have this gem installed and set the adapter in your database.yml to "mysql2".
0 commit comments