MATLAB: Database query is slow in R2018a

databaseDatabase Toolboxfetchbatchsizefetchinbatchesrowincrunsqlscript

I was using in R2016b the following code to connect to an oracle database:
>> conn = database.ODBCConnection(prod,serv,pswd);
>> setdbprefs('FetchInBatches','yes')
>> setdbprefs('FetchBatchsize','10000')
>> data = runsqlscript(conn,'SQL_query.sql');
It used to take 2 seconds.
Now that I tried to run it in R2018a it doesn't recognize the 'FetchInBatches' or 'FetchBatchsize' commands so I'm just running the code as
>> conn = database(prod,serv,pswd); % aparently .ODBCConnection syntaxis is depricated
>> data = runsqlscript(conn,'SQL_query.sql');
The query takes 3 minutes now!
I haven't been able to find in the documentation how to make my query faster. Could you please let me know how to fix this and make my query run fast again?

Best Answer

In R2016b, you used _setdbprefs _to fetch data in batches.
Retrieving data in batches reduces overall retrieval time.
Now, setdbprefs('FetchBatchSize','1000') and _setdbprefs('FetchInBatches','yes') _have been deprecated in R2018a (Refer Release Notes for more details).
So, while querying database, it is taking more time than it used to.
You can use '_*RowInc*_' nave-value pair in runsqlscript.
_*RowInc *_is row limit indicating the number of rows to retrieve at a time, specified as the comma-separated pair consisting of 'RowInc' and a positive numeric scalar.
Use this name-value pair argument when importing large amounts of data. Importing data in increments helps reduce overall retrieval time.
By default, the _runsqlscript _function imports all rows of data from the executed SQL statements. The value 0 specifies to import all rows of data.
data = runsqlscript(conn,'SQL_query.sql', 'RowInc', 1000);
Hope this helps!