Slow ODBC driver or programming error?
I have a query that returns 1000 rows in about 5 secs on a local network.
Exactly the same query takes about 5 mins to complete across the internet(fast one).
I am using odbc driver against MSSQL database.
I suspect that the code I wrote to retrieve records might be the problem.
Code:
{
// db is an instance of QSqlDatabase, correctly initialized.
try
{
retval->setQuery(sql, db);
while (retval->canFetchMore())
retval->fetchMore();
return retval;
}
catch (...)
{
return NULL;
}
}
Any advice/comment will be appreciated.
Re: Slow ODBC driver or programming error?
Yeah, skip the while() loop :)
Re: Slow ODBC driver or programming error?
If you need a true row count, which is often the reason for the while loop, then it will be more efficient to run a specific query to get the row count and then let Qt's lazy fetching fetch the actual rows only when/if they are needed in a view.
Re: Slow ODBC driver or programming error?
You can also use setForwardOnly() to make some queries faster.
Regards,
Marc
Re: Slow ODBC driver or programming error?
Quote:
Originally Posted by
wysota
Yeah, skip the while() loop :)
Can you explain why? A single query request returns 256 rows in my case. I know that there are 1000+ results, so I am fetching all results from the database.
Re: Slow ODBC driver or programming error?
Quote:
Originally Posted by
TorAn
I am fetching all results from the database.
That's exactly why. You are fetching a lot of data which blocks your app.
Re: Slow ODBC driver or programming error?
1017 records is a lot of data?
When this call is executed on the machine where db is located it takes about 2 secs.
When it is executed on the LAN it takes about 4 seconds. When I am on WAN (public), it takes literally 5 minutes. The same sql request through SQL Management studio takes 2 secs on LAN and 2-4 secs on WAN.
Re: Slow ODBC driver or programming error?
Blame your ODBC driver. Qt driver is optimized for what it does, if you want to force it to load all the rows even if it doesn't want to, you probably get additional queries which slow down everything. Use a better driver or skip the unnecessary while loop.
Re: Slow ODBC driver or programming error?
Quote:
Blame your ODBC driver
That's what I am doing.
Which driver do you recommend? FreeTDS?
Re: Slow ODBC driver or programming error?
Use the driver most fit for your database. However I would first think whether I really needed this while loop. It seems not necessary.