Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-08

TQuery.Open 100x slower than same code using PostrgreSQL

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Howard Lee Harkness

Now I'm seeing a very slow response to opening the main table, even with no dependent tables.

I set the SQL in the TQuery, then do an open. It takes 4 to 6 seconds to populate the TDBGrid. When I was using PostgreSQL with the same database, it was instant.

  qClients.Close;
  qClients.SQL.Text:='select * from clients where lastname is not NULL
order by lastname,firstname,middlename';
  qClients.Open; // takes 4 to 6 seconds here

There has GOT to be something I'm not understanding. I thought SQLite was going to speed things up, not slow them down.

Howard Lee Harkness wrote 84 lines
I have added some code to only open a query if the corresponding tabsheet is selected, which I think speeds things up sufficiently. Still would like to know why a TQuery component would take 2 or 3 seconds to open, even on a slow machine. Here is the SQL from my address table query: select * from addresses where ID = :ID order by atype,asof "atype" is a string (home, work, etc.) and "asof" is a date. The SQL for the other two queries is very similar. In the synchronization procedure to set the :ID value for each query: ? closeDependentQueries; ? CurrentClientID := qClients.FieldByName('ID').AsInteger; ? qAddresses.Params.ParamByName('ID').Value := CurrentClientID; ? qCases.Params.ParamByName('ID').Value := CurrentClientID; ? qPhones.Params.ParamByName('ID').Value := CurrentClientID; I have not yet played around with the foreign key stuff, and I'm not really sure how to enable & use foreign keys in SQLite, anyway. On Mon, Aug 1, 2011 at 4:21 PM, Howard Lee Harkness wrote: > I have a dummy database and complete program I can let you look at if > you would like. Nothing particularly proprietary about the code; it's > a trivial application. The database is the sensitive part, and I have > it dummied out. > > I posted the schema a few days ago, and I've added a zipcode table to > that. I had initially thought I had solved the performance problem, > but when I got to the client, and ran it on his machine (which is > about 100x slower than mine). I had not noticed the lag on my machine, > but it was really awful on his. > > The whole project is in a 1.6Mb zip, expands to just over 7Mb. Would > you like me to email it directly to you, or post it? > > On Mon, Aug 1, 2011 at 1:56 PM, Michael Van Canneyt > wrote: >> >> >> On Mon, 1 Aug 2011, Howard Lee Harkness wrote: >> >>> I thought I had fixed the performance problem, but it is still there. >>> What I am doing is opening 3 dependent queries after selecting a >>> record in the main table. It takes 8 or 9 seconds to do the 3 calls to >>> TQuery.Open. Any clues as to what I might be doing wrong? The sample >>> queries done from sqlite3.exe return instantaneously, so I am >>> concluding that I have not set something up correctly in the LCL. >> >> Can you provide test data and a sample program ? Without that, it's very >> hard to give recommendations. >> >> The architecture of the sqlite components is not fundamentally different >> from >> the other database, and those do work instantaneously. >> >> Michael. >> >> -- >> _______________________________________________ >> Lazarus mailing list >> >> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus >> > > > > -- > Howard Lee Harkness > (214) 390-4896 > -- Howard Lee Harkness (214) 390-4896
Howard Lee Harkness (214) 390-4896

Reply by email

Martin Schreiber
to Howard Lee Harkness
Howard Lee Harkness wrote 12 lines
Now I'm seeing a very slow response to opening the main table, even with no dependent tables. I set the SQL in the TQuery, then do an open. It takes 4 to 6 seconds to populate the TDBGrid. When I was using PostgreSQL with the same database, it was instant. qClients.Close; qClients.SQL.Text:='select * from clients where lastname is not NULL order by lastname,firstname,middlename'; qClients.Open; // takes 4 to 6 seconds here

In MSEgui with your 10000 records test DB:

"
select * from clients where lastname is not null order by lastname,firstname,middlename;
"
0.029s, returning 10 records, see attachment.

"
select * from clients where lastname is null order by lastname,firstname,middlename;
"
0.716s, returning 9990 records.

"
select * from clients where lastname is null;
"
0.371s, returning 9990 records.

"
select * from clients;
"
0.331s, returning 10000 records.

The times include fetching the whole resultset (packetrecords = -1) and the population of the grid.

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sqliteperf.png
Type: image/png
Size: 20481 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110807/831447be/attachment-0001.png>

Reply by email

Ludo Brands
to Howard Lee Harkness: Now I'm seeing a very slow response to opening the main table, even with no dependent…
There has GOT to be something I'm not understanding. I thought SQLite was going to speed things up, not slow them down.

Clearly you are not providing enough information to reproduce the problem. So far it has all been guess work for people trying to help. Fe. your initial request for help "forgot" to mention that there were several dependant queries. If you upload the project we can take a aren't needed. Populating with random data is easy. Seen the size of your project (I guess this mailing list has attachment size limits) upload it somewhere and post the link.

Ludo

Reply by email

Howard Lee Harkness
to Ludo Brands

After several hours (over a period of a couple of months) of battling this problem, I finally found the cause. I was not looking in the right place. Turns out that I had a dependent query that were being opened after the client TQuery. Actually, there were 3 different dependent queries, only one of which was causing the problem. On my system, I never ran into the problem, primarily because my testing was not comprehensive enough -- and the attorney ran into it almost immediately every time he used it (and he just complained that it was too slow). I finally just recorded *exactly* what he was doing, and then easily duplicated the problem.

The problem query was the "cases" table, which has a client ID foreign key, an OID (primary key), a date and a large text field. PostgreSQL did not have any slowdown at all with this database schema, so I was surprised to see that SQLite took two orders of magnitude longer to open that same table.

What I did was simply close the case table whenever doing the incremental search. That works, although it seems to be a bit of a hack.

Ludo Brands wrote 22 lines
> > There has GOT to be something I'm not understanding. I > thought SQLite was going to speed things up, not slow them down. > Clearly you are not providing enough information to reproduce the problem. So far it has all been guess work for people trying to help. Fe. your initial request for help "forgot" to mention that there were several dependant queries. If you upload the project we can take a aren't needed. Populating with random data is easy. Seen the size of your project (I guess this mailing list has attachment size limits) upload it somewhere and post the link. Ludo -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Howard Lee Harkness (214) 390-4896 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120206/5ee8c876/attachment.html>

Reply by email