sub Obtain_GeoIP { $GeoIP_resolved++; $Scountry=""; $Dcountry=""; my ($IP) = @_; if($IP=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/ &&(($1< +=255 && $2<=255 && $3<=255 &&$4<=255 ))) { my $sip = 0; my @sip = split(/\./,$IP); if (($sip[0] == "10") || ($sip[0] == "192" && $sip[1] == "168" +) || (($sip[0] == "172" && $sip[1] >= "16") && ($sip[0] == "172" && $ +sip[1] <= "31"))) { return "Internal Network"; } else { if ( exists $geoip_hash{IP} ) { my $country_hash = $ge +oip_hash{IP}; return $country_hash; } my $lip = ( ($sip[0]*($n * $n * $n))+($sip[1]*($n * $n +))+($sip[2] * $n) + ($sip[3]) ); # my $obtain_country = $dba->prepare("select Country f +rom GeoIP where ('$lip' > Start_int) and ('$lip' < End_int) limit 1") +; my $obtain_country = $dba->prepare("select Country fro +m GeoIP where $lip between Start_int and End_int limit 1"); $obtain_country->execute(); my @country = $obtain_country->fetchrow(); $obtain_country->finish; chomp @country; $geoip_hash{$IP} = $country[0]; return $country[0]; } } else { print EFILE "IP address sent to Obtain_GeoIP routine w +as incorrect: $IP - $counter\n"; } } mysql> explain select Country from GeoIP where ('2345565466' > Start_i +nt) and ('2345565466' < End_int) limit 1; +----+-------------+-------+-------+-------------------+-----------+-- +-------+------+-------+-------------+ | id | select_type | table | type | possible_keys | key | k +ey_len | ref | rows | Extra | +----+-------------+-------+-------+-------------------+-----------+-- +-------+------+-------+-------------+ | 1 | SIMPLE | GeoIP | range | Start_int,End_int | Start_int | 5 + | NULL | 40541 | Using where | +----+-------------+-------+-------+-------------------+-----------+-- +-------+------+-------+-------------+ 1 row in set (0.00 sec) mysql> desc GeoIP; +------------------+------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------+------------------+------+-----+---------+-------+ | Start_int | int(10) unsigned | YES | MUL | NULL | | | End_int | int(10) unsigned | YES | MUL | NULL | | | Country_Initials | varchar(3) | YES | | NULL | | | Country | varchar(30) | YES | | NULL | | +------------------+------------------+------+-----+---------+-------+ 4 rows in set (0.01 sec)
In reply to Slow response on DBI MySQL query by Fortificus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |