Current location: Hot Scripts Forums » Programming Languages » PHP » mysql slow searching


mysql slow searching

Reply
  #1 (permalink)  
Old 11-30-09, 06:01 AM
anacy_nivas's Avatar
anacy_nivas anacy_nivas is offline
Newbie Coder
 
Join Date: Sep 2008
Location: coimbatore
Posts: 47
Thanks: 11
Thanked 0 Times in 0 Posts
mysql slow searching

Hi,
I am doing destance search from GEO database query like following

SELECT *,(((acos(sin((46.6333*pi()/180)) * sin((`lat`*pi()/180))+cos((46.6333*pi()/180)) * cos((`lat`*pi()/180)) * cos(((14.5333- `lon`)*pi()/180))))*180/pi())*60*1.1515*1.609344) as distance FROM `geodb_coordinates` as as1 , geodb_textdata as as2 where as1.loc_id=as2.loc_id and as2.text_type=400300000 and text_locale='de' having distance < 200


i have totally 40500 records each table, result for this query is very slow to display , i am waiting long time but still i cannot get.. what is the problem here, please explain any one.

Last edited by anacy_nivas; 11-30-09 at 06:03 AM. Reason: for title replace
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-30-09, 07:19 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
Way too much computation on the query.

Post the schema (describe geodb_coordinates).

My approach to this type of query (it was geolocation) was to compute out a square with the four corners that indicated the area within the query, then search for lat/long within those areas.

Something similar to

Code:
distance=miles converted to lat/long measurements
min_lat=target latitude-distance/2
max_lat=target latitude+distance/2
min_lon=target longitude+distance/2
max_lon=target longitude+distance/2
select from geodb_coordinates where lat>min_lat and lat<max_lat and lon>min_lon and lon<max_lon
In this case, the complex computation is only done once, and used to define the range of acceptable coordinates.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to wirehopper For This Useful Post:
anacy_nivas (11-30-09)
  #3 (permalink)  
Old 11-30-09, 07:25 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Any chance that there is Zip code data attached to the Lat/Long coordinates? If so, there are a number of easy ways to do this. There's also this function I use:

PHP Code:

  function calculate_mileage($lat1$lat2$lon1$lon2) {

 
      
// used internally, this function actually performs that calculation to
      // determine the mileage between 2 points defined by lattitude and
      // longitude coordinates.  This calculation is based on the code found
      // at http://www.cryptnet.net/fsp/zipdy/
       
      // Convert lattitude/longitude (degrees) to radians for calculations
      
$lat1 deg2rad($lat1);
      
$lon1 deg2rad($lon1);
      
$lat2 deg2rad($lat2);
      
$lon2 deg2rad($lon2);
      
      
// Find the deltas
      
$delta_lat $lat2 $lat1;
      
$delta_lon $lon2 $lon1;
    
      
// Find the Great Circle distance 
      
$temp pow(sin($delta_lat/2.0),2) + cos($lat1) * cos($lat2) * pow(sin($delta_lon/2.0),2);
      
$distance 3956 atan2(sqrt($temp),sqrt(1-$temp));

      return 
$distance;
   } 
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to End User For This Useful Post:
anacy_nivas (11-30-09)
  #4 (permalink)  
Old 11-30-09, 08:10 AM
anacy_nivas's Avatar
anacy_nivas anacy_nivas is offline
Newbie Coder
 
Join Date: Sep 2008
Location: coimbatore
Posts: 47
Thanks: 11
Thanked 0 Times in 0 Posts
sure, thanks

i have attached schema please see the attachment.
Attached Images
File Type: gif describe.gif (10.8 KB, 94 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 11-30-09, 08:16 AM
anacy_nivas's Avatar
anacy_nivas anacy_nivas is offline
Newbie Coder
 
Join Date: Sep 2008
Location: coimbatore
Posts: 47
Thanks: 11
Thanked 0 Times in 0 Posts
function calculate_mileage ..

I think using "calculate_mileage" function , i need to select all records (total 40500) then filter .
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
login, roles problem dbrook007 ASP.NET 10 11-10-06 04:42 PM
Form Display Problem neevrap02 Visual Basic 1 09-05-06 06:18 AM
DTS speed problem! Naresh Rohra Visual Basic 1 03-01-06 09:47 AM
Asp and Microsoft Access 2002 problem gop373 ASP 2 10-06-04 10:13 AM


All times are GMT -5. The time now is 12:22 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.