Delphi Firebird speed problem
Posted on 2008-10-29
I develop an application in Delphi 7 using a firebird database. I have a big problem with speed in a select statement that i use after i insert into a table some records.I insert records into the table and everything is ok with speed if i don't select anything after this and doesn't matter how many records i have into this table but when i select some data because i want to present them into a dbgrid and to take some totals into editboxes and i have more than 500 records the query takes more than 4 seconds to executed!!!
This table could be have thousands of records and now i have more than 100,000 records.
Here is an example of the source code:
//here i insert records
ibquery2.sql.Append('INSERT INTO table (var1,var2,var3) VALUES (test,test,test);
//here I select some data for the dbgrid and here starts the speed problem if I have many
//records into the table as i said before
//the query executed into 2 or 3 secs
ibquery2.sql.Text:='select id,pid,var1,var2,var3 from table where id=' + label5.Caption + ' order by id,pid ASC';
//and here the speed problem seems to be very big
//the query executed into 4 or 5 secs
ibquery4.SQL.Text:='select sum(var1) from table where id=' +label5.Caption + ' AND level=1';
ibquery4.SQL.Text:='select sum(var2) from table where id=' +label5.Caption + ' AND level=1';
Help me about what i am doing wrong and i have these speed problems and what i have to do to fix this.
Thanks in advance.