Topic: [Solved] - Comparing array values with...
Hello Dmitry and all MVD fans,
I feel a bit dumb with my question because I have a valid solution to my problem, but it is so long that I would like to speed up the process.
Here is the situation :
1- From a web site, I get a string, delimited by comas, containing a long list of reference numbers. When I say long, I'm talking about more than 25.000 items. They are handled as text
2- I split this string into an array
3 - for each value of the array, I query the database looking for a match.
It looks like this :
var
i, known : Integer;
begin
for i := 0 to Length(sku_array) - 1 do
begin
known := SQLExecute('SELECT COUNT(id) FROM asset WHERE asset_sku = "'+sku_array[i]+'"');
if known = 0 then <some code> else <some other code>;
end;
end;
This is my code, it works, I'm even proud of it , but it's sooooooooooo slow !!
On a core i7 machine, running the system on a SSD drive, it can take up to 10 minutes to loop through all the results. To long for checking this on a daily basis.
So, to speed up the process, I thought about :
- handling the comparison in memory
- avoiding 25.000 queries and using just one to create a Dataset;
This way, once all the data in memory (RAM), the comparison should be quicker, right ?
So I imagined something like :
var
sku_array : Array of String;
Results : TDataSet;
i : Integer;
begin
SQLQuery('SELECT asset_sku FROM asset',Results);
While not Results.Eof do
begin
for i := 0 to Length(sku_array) - 1 do
begin
if sku_array[i] = Results.FieldByName('asset_sku').AsString then <some code> else <some other code>;
end;
Results.Next;
end;
Results.Free
end;
And when I launch it, it loops and loops and loops.... I've killed the process each time before the end, but I suspect it's going to loop something like 25.000 x 25.000 times
So I made some research, and tried plenty of others things but failed miserably....
What would be the best way to achieve this, keeping in mind that what I want to detect are array values (from the web page) that are not present in my database (the dataset) ?
I don't need a full example, pseudo code with the main logic could do the trick.
Thank you all for your assistance, I'll post processing time comparisons when I'll have the solution
Cheers
Mathias
Each time I get a divorce, I keep the house
Zaza Gabor