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
Speed retrieving one record from large table
-
miguelenguica
- Posts: 18
- Joined: Mon 11 Apr 2011 15:28
-
AndreyZ
Hello,
The fastest way to get records from a big table without obtaining it on a client computer is to use a query like:Also please read the "Increasing Performance" topic of the MyDAC documentation. There you will find several suggestions for speeding up your application.
The fastest way to get records from a big table without obtaining it on a client computer is to use a query like:
Code: Select all
MyQuery.SQL.Clear;
MyQuery.SQL.Add('select field1, field2 from tablename'); // select only needed data
MyQuery.SQL.Add('where field3 = :value1, field4 = :value2'); // you should have an index that includes field3 and field4
MyQuery.Prepare; // to increase performance-
miguelenguica
- Posts: 18
- Joined: Mon 11 Apr 2011 15:28
-
AndreyZ
Please try using the USE INDEX statement. You can find more information about it here: http://dev.mysql.com/doc/refman/5.0/en/index-hints.html
Execution of a query one hundred times is always slower than performing the Locate function one hundred times on a client machine, because requests to the server require time (connection establishment, network speed).
Execution of a query one hundred times is always slower than performing the Locate function one hundred times on a client machine, because requests to the server require time (connection establishment, network speed).
-
miguelenguica
- Posts: 18
- Joined: Mon 11 Apr 2011 15:28