sqlsrv driver

These changes work with sql server 2012 and above.
FreeTDS
Set up an installation that uses the FreeTDS driver to connect to a mssql database.
Add a course and log in and out with some students to create some logs.
Run memory.php to create a lot of log entries. This is a CLI script so it needs to be run from the command line.
Make sure that your memory_limit in php.ini is around 64M.
Go to [Site administration ► Reports ► Logs] and get the default logs
Click on one of the page links at the top of the table. Click one that is above 3000.
Before, the page would only partially load. Now check that the page fully loads.
sqlsrv driver
Create a similar setup on a system that is not using FreeTDS but is connecting to an MSSQL database.
Check that paging in the log report works as above.

Description

When standard log (logstore_standard_log table) contains more than... not sure.. but between 300.000 and 700.000 records and I run report_log, setting &page param to ~more than 3000 (~1000 for Rajesh) the page just returns a white screen or it just renders the filters. It is crashing in get_events_select, but it does not matter if it is a get_recordset a get_records, if it returns an iterator, an array... It always crashes

Setting memory_limit to unlimited "fixes" the problem, but all the other drivers just need around 32/64MB to download hundreds of thousands of records (after MDL-48595)

I remember Eloy commenting about some db drivers not being friendly with recordsets, I understand that it is Mssql as using an oracle I could download a 100MB logs csv.

Opening this issue in case there is any workaround this.

I set affect versions as 2.9 but probably 2.8 and 2.7 are also affected.