geolocation - Mysql Join on three tables containing spatial data -
geolocation - Mysql Join on three tables containing spatial data -
i have 3 tables
outlets (shopid, shopname,shoplatitude,shoplongitude,g) (450 rows)
g of type geometry , contains value point(latitude longitude)
offers (offerid,offername,offerdescription) (450 rows)
offer_outlets
(offerid,shopid) (503 rows)
i want fetch offers , shop details within particular radius, next tutorial implementing spatial queries.
here query using working fine few 100's of records, above mentioned number of items in each table taking 34s homecoming results. how can efficiently write query?
select distinct ofr.offerid,ofr_otl.shopid,ofr.isdeleted,ofr.offer_title,ofr.offer_icon, ofr.offer_description,ofr.categoryid,ofr.offer_terms, ofr.start_date,ofr.end_date, ofr.price_description, otl.shop_name,otl.shop_address,otl.shop_city, otl.shop_phone,otl.shop_icon, otl.shop_latitude,otl.shop_longitude,otl.shop_country,otl.shop_zip, get_distance(x(g),y(g),8.4901831,76.9558434) distance, otl.shop_weblink, ofr.off_angle,ofr.rating offers ofr,outlets otl,off_outlets ofr_otl ofr.offerid = ofr_otl.offid , otl.shop_id = ofr_otl.shopid , st_within(g,envelope(linestring( point(8.039914120289854, 76.5005853263206), point(8.940452079710145, 77.41110147367941)))) , ofr.isdeleted = 0 order offer_title limit 300 ;
try this:
select ... ( select * ( select * outlets a.shoplatitude between ( ... ) , a.shoplongitude between ( ... ) ) t1 st_within(t1.g, ... ) ) otl left bring together off_outlets oo on otl.shop_id = oo.shopid left bring together offers ofr on ofr.offerid = oo.offid ofr.isdeleted = 0 order offer_title limit 300 ;
it forces mysql first filter shops out within latitude/longitude rectangle, then on st_within, then rest.
mysql geolocation mysql-spatial
Comments
Post a Comment