Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 3rd Apr 2016, 04:48 PM   #1
Senior Warrior
War Room Member
 
Michael D Price's Avatar
 
Join Date: 2002
Location: Mobile, Al
Posts: 23
Thanks: 23
Thanked 16 Times in 14 Posts
Default
HELP!!! Need Database Expert, Please
Share on: 
fb share twitter share gplus share more share

Hello All,

Wow this place has changed!

Anyway, down to business ...

I have a problem. I have developed an online script that will allow its users to perform a database search for the number of records within a radius of a given zipcode.

The results of this query must match (close enough) with the results of the same query using AccuZip software.

So far it functions exactly as it should, the way the calculations are performed, However it is too slow.

Currently taking over 9 seconds ...

Can someone take a look at the query, and make suggestions on how to improve upon it, to speed it up ...


-------------------
SELECT COUNT(*) as COUNT FROM (

SELECT unique_id, lat,lon,(((acos(sin((34.099800*pi()/180)) * sin((`lat`*pi()/180))+cos((34.099800*pi()/180)) * cos((`lat`*pi()/180)) * cos(((-118.412003- `Lon`)*pi()/180))))*180/pi())*60*1.1515) as distance FROM records)

as result WHERE distance <= 150;
-----------------------------

Any takers? the 150 is 150 mile radius, and the starting point is 34.099800,-118.412003
Michael D Price is offline  
Unread 4th Apr 2016, 09:08 AM   #2
HyperActive Warrior
 
javrsmith's Avatar
 
Join Date: 2011
Location: British Columbia, Canada
Posts: 132
Thanks: 181
Thanked 45 Times in 40 Posts
Default
Re: HELP!!! Need Database Expert, Please
Share on: 
fb share twitter share gplus share more share

You need to partition the data faster. Right now it's calculating for every record, even those located thousands of miles away.

Are you able to partition faster? Perhaps you could add a clause to say "and substring('POSTAL',1,2) = '60'" This would let the database narrow down to the Chicago area right away. "98" for Seattle, etc.
If you don't have postal, you might want to roughly calculate it in a batch job and store with each record.

Alternatively, if the starting point is known when the record is created, you could store DISTANCE during the initial add. If the starting point is variable, this might not work. Maybe you have a limited number of starting points. You could store DISTANCE1, DISTANCE2, etc.

I also see that the calculation "34.099800*pi()/180" is being performed twice for this query. You could pre-calculate this into a constant variable. I would also use "3.14159" for pi, eliminating 6 calls to the function.
javrsmith is offline  
Unread 5th Apr 2016, 03:50 AM   #3
Bananas are Yellow!
Registered Member
War Room Member
 
David Beroff's Avatar
 
Join Date: 2013
Location: Wyoming, PA, USA
Posts: 1,046
Thanks: 2,549
Thanked 1,600 Times in 928 Posts
Blog Entries: 4
Default
Re: HELP!!! Need Database Expert, Please
Share on: 
fb share twitter share gplus share more share

Continuing on javrsmith's idea, I'd precede the complex calculation with a simple check on the containing rectangle. i.e., If it's not in the rectangle, don't even bother doing the trig.

Put MY voice on YOUR video: AwesomeAmericanAudio.com
David Beroff is offline  
Closed Thread


Bookmarks

Tags
database, database optimization, expert, geo location, mysql database


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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 03:33 PM.