Home > Back-end > Daniel for help ah.. Delphi query the database too slow, how to solve the code [with]
Daniel for help ah.. Delphi query the database too slow, how to solve the code [with]
Time:09-29
Code from the table biao, according to ziduan lookup, and returns the x1, x2 two values, assign jieguo1, jieguo2
A:='emample'; For I=1 to 400 do//test run 400 The begin ADOQuery1. Close; ADOQuery1. SQL. Text:='select x1, x2 from biao where ziduan=' "+ a +" '"'; ADOQuery1. Open;
Jieguo1:=ADOQuery1 FieldByName (' x1). AsString;//the removed, the running time no optimization Jieguo2:=ADOQuery1 FieldByName (' x2). AsString;//the removed, the running time no optimization
end;
Biao about 20000 data, ziduan, x1, x2 length is not more than 5 characters, Test the above code, you want to run three and a half seconds, The speed is too slow, Daniel, help have a look at how to solve
CodePudding user response:
ADOQuery1. Close; ADOQuery1. SQL. Text:='select x1, x2 from biao where ziduan=' "+ a +" '"'; ADOQuery1. Open;
Jieguo1:=ADOQuery1 FieldByName (' x1). AsString;//the removed, the running time no optimization Jieguo2:=ADOQuery1 FieldByName (' x2). AsString;//the removed, the running time no optimization -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Perform a 3 seconds?
CodePudding user response:
For ziduan field to establish a clustering index index, see speed of ascension
CodePudding user response:
A:='emample'; For I=1 to 400 do//test run 400 The begin //the following three to write inside the loop behavior? Once found to need the assignment respectively? ADOQuery1. Close; ADOQuery1. SQL. Text:='select x1, x2 from biao where ziduan=' "+ a +" '"'; ADOQuery1. Open; Jieguo1:=ADOQuery1 FieldByName (' x1). AsString;//the removed, the running time no optimization Jieguo2:=ADOQuery1 FieldByName (' x2). AsString;//the removed, the running time no optimization
end;
CodePudding user response:
Some look not to understand the code, This is just the table opened the 400 times!
Every time to check the results are the same, why not check only once?
CodePudding user response:
Well, yes, this is to test the code above, 400 times is equivalent to access the database, took three seconds, (in fact, in to the client program, he enter a value, to check the database 1200 times, what I use is the code above, about 9 seconds, the time is too long),
Just in the access to the "ziduan" to build an index, speed is quick, run 400 times is about 1.5 seconds,