Posted by Cleverbum on 12/12/06 09:14
Toby Inkster wrote:
> Rik wrote:
>
> > Indeed, or possibly check it first:
> > $searchstring = md5(//something);
> > $result = mysql_query("SELECT `textmd5` FROM `logs_full` WHERE `textmd5` =
> > '{$searchstring}'");
> > if(mysql_num_rows($result) < 1){
> > //not in table logic..
> > } else {
> > //is in table logic..
> > }
>
> As the OP said, he needs to check "hundreds of thousands" of md5 strings
> -- using an SQL call for each one will slow him down.
Hit the nail on the head.
>
> My advice would be to keep doing roughly what you're already doing, but
> speed up your array search.
>
> To speed up your search, make sure your array is sorted in alphabetical
> order. You can do this using your initial SQL query:
>
> SELECT textmd5 FROM logs_full ORDER BY textmd5;
>
> (Note: the query will speed up by specifying the exact column you need to
> select; not '*'.)
>
> You can then use a binary search function[1] instead of in_array() to
> check that a value exists in your array.
>
> ____
> 1. Such as...
> http://www.rci.rutgers.edu/~jfulton/binary_search/binary_search.inc
>
> --
> Toby A Inkster BSc (Hons) ARCS
> Contact Me ~ http://tobyinkster.co.uk/contact
Thanks for the binary search idea I've done some timing and the
in_array seems to be taking a lot longer than I originally thought it
would.
[Back to original message]
|