I am trying to analyze network traffic. The traffic is saved into an approximately 300MB-SQLite file, which I am trying to comb for keywords.
I have about 10 keywords, for which I generate mutations (reverse string, hashes, etc.), which amounts to approximately 20 variants per keyword. In order to find those permutations, I generate a query for each keyword that includes all the permutations in one command, separated by OR. One query looks like this:
SELECT * FROM flows
WHERE
(buffer LIKE :permutationOne) OR
(buffer LIKE :permutationTwo) OR
(buffer LIKE :permutationThree) OR
…
(buffer LIKE :permutationTwenty)
The initialization of the SQLite communication and the statement binding looks like that:
$sqlite = new PDO('sqlite:resources/traffic.sqlite'); // executed once
// done for each keyword
$statement = $sqlite->prepare($sqlCommand);
$statement->execute([':permutationOne' => '%perm1%', ':permutationTwo' => '%perm2%', …]);
I measured the time the execution of these ten queries takes, and it varies between 150 and 300 seconds, depending on the device the query is executed on. As the file is big and I execute 10 queries with 20 like-strings each, I was wondering whether there was a way I could optimize the query? I would very much like to at least halve the execution time, if that is possible. Or maybe I should use another library rather than PDO?