Speed retrieving one record from large table
Posted: Sat 16 Apr 2011 16:14
Hi. I have a large MySQL table (5.000.000 records). My application must retrieve individual (sometimes 2 or 3) records intensively. With a TMyQuery using the correct indexes in a sequence
MyQuery.Params[];
MyQuery.Open;
while not MyQuery.eof do
(...)
MyQuery.Close;
It just takes a lot of time (4 or 5 seconds).
On the second case I use a TMyTable or a TMyQuery with no params and opened at startup, with the right index. The I just use TMyTable or TMyQuery.Locate and the results are instant. i can perform hundreds of locates under 1 second. The only problem is that it just takes a lot of time at startup.
The second case works, but it just cant't be thread safe. Is there anyway I can have the same locate speed with just runtime select? What would be the best way to implement this?
Thanks,
Miguel
MyQuery.Params[];
MyQuery.Open;
while not MyQuery.eof do
(...)
MyQuery.Close;
It just takes a lot of time (4 or 5 seconds).
On the second case I use a TMyTable or a TMyQuery with no params and opened at startup, with the right index. The I just use TMyTable or TMyQuery.Locate and the results are instant. i can perform hundreds of locates under 1 second. The only problem is that it just takes a lot of time at startup.
The second case works, but it just cant't be thread safe. Is there anyway I can have the same locate speed with just runtime select? What would be the best way to implement this?
Thanks,
Miguel