PDA

View Full Version : long query executing



banita
8th October 2010, 13:56
I execute query wich take about 5-6min. When I do this my application is freeze. Is there any chance to avoid this?

I use firebird embeded database so I cant execut query in other thread.

sory for my poor english.

wysota
8th October 2010, 15:26
Why can't you execute the query in another thread?

Davton
8th October 2010, 16:02
Yes, why not?
Because execute your request in another thread is your only chance.
You execute your request from the qt main loop (HMI thread) so your HMI is frozen until the request isn't finished.

With a little bit of chance, and if you can do that, you can call QCoreApplication::processEvents() (static method)
each time you can while you're executing your long treatment so the main loop will (try) to execute HMI request waiting for execution.
Your HMI will execute some events (refresh some values for example) but your HMI will still look as frozen...

Good luck

banita
8th October 2010, 16:55
I cant use another thread because when I execute query I have open some sql table and cant close it. I use embeded firebird so I cant manage another connection to databse for second thread.
Also I cant use rocessEvents() because I execute one statement (not in loop) and firebird engin do all work.

wysota
8th October 2010, 22:43
If you do all queries in a separate thread, you don't have to worry about leaving an open table in the main thread.

banita
9th October 2010, 12:53
so is it safe to do queries in separate thread with connection from main thread?

I know I cant use one connection object for two queries running in the same time from two different threads.

wysota
9th October 2010, 14:58
so is it safe to do queries in separate thread with connection from main thread?
If you're using Qt's SQL infrastructure then no but you can open the connection from the worker thread, right?

banita
9th October 2010, 16:03
Should I create and open connection (con1) in thread which I use to execut queries?
If I do that is it safe to use this connection(con1) to open and view sql table in main thread?

wysota
9th October 2010, 16:53
Should I create and open connection (con1) in thread which I use to execut queries?
Yes.

If I do that is it safe to use this connection(con1) to open and view sql table in main thread?
No, it isn't.

banita
9th October 2010, 21:49
so it is impossible to have open sql table in main thread and execute queries in other thread when I have one connection object. I cant close my table so I cant execute query in other thread(cant create another connection).

wysota
10th October 2010, 09:11
so it is impossible to have open sql table in main thread and execute queries in other thread when I have one connection object. I cant close my table so I cant execute query in other thread(cant create another connection).

You can fetch the data for the table from the thread too. If that's not enough for you then sorry, you're out of luck.

ChrisW67
11th October 2010, 00:38
Is Firebird really limited to a single connection or am I missing something here? That doesn't seem to be the case from a quick glance at the docs.

5 or 6 minutes to execute a single query on an embedded database seems a bit excessive. Is it trawling through billions of records or doing some convoluted outer-joining monstrosity? Can you do anything to speed this up? Indexes, temporary intermediate tables, split the work into stages etc.