Joins on spatial mysql indexes

后端 未结 4 2027
攒了一身酷
攒了一身酷 2021-02-08 03:59

I have two tables: one with points, the other with polys.

CREATE TABLE `points` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `point` point NOT NULL,
  PR         


        
4条回答
  •  北海茫月
    2021-02-08 04:42

    I have used successfully similar queries, with only one difference in data model: a spatial key on the points database. In my case:

    CREATE TABLE geopoints (
      pid int(11) NOT NULL AUTO_INCREMENT,
      description varchar(255) NOT NULL DEFAULT '',
      geopoint point NOT NULL,
      PRIMARY KEY (pid),
      SPATIAL KEY geopoint (geopoint) 
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    

    And everything went well in queries like this:

    SELECT pt.pid, x(geopoint), Y(geopoint), pl.pid, AsText(geopolygon) 
      FROM geopoints pt INNER JOIN geopolygons pl ON MBRCONTAINS(geopolygon, geopoint)
     WHERE pt.pid IN (1,2,4,5) AND pl.pid BETWEEN 1 AND 5;
    

    my two cents,

提交回复
热议问题