There is one caveat in my solution:
1) , MyISAM . MyISAM, , MyISAM .
, , , :
MySQL (. ). , MyISAM R-Tree (. ), . , , .
, , GeoIP. , , .
, / : , 0,0 xy, , , , , . , . , .
:
1) MyISAM ( , , , , MyISAM).
alter table events engine = MyISAM;
2) , . , .
alter table events add column time_poly polygon NOT NULL;
3) ( , , , , , ). , unix_timestamp (. , ).
update events set time_poly := LINESTRINGFROMWKB(LINESTRING(
POINT(unix_timestamp(start_time), -1),
POINT(unix_timestamp(end_time), -1),
POINT(unix_timestamp(end_time), 1),
POINT(unix_timestamp(start_time), 1),
POINT(unix_timestamp(start_time), -1)
));
4) ( , MyISAM "ERROR 1464 (HY000): SPATIAL" ).
alter table events add SPATIAL KEY `IXs_time_poly` (`time_poly`);
5) , .
SELECT *
FROM events force index (IXs_time_poly)
WHERE MBRCONTAINS(events.time_poly, POINTFROMWKB(POINT(unix_timestamp('2009-02-18 16:27:12'), 0)));
100% , MySQL . , select - :
mysql> explain SELECT *
-> FROM events force index (IXs_time_poly)
-> on MBRCONTAINS(events.time_poly, POINTFROMWKB(POINT(unix_timestamp('2009-02-18 16:27:12'), 0)));
+----+-------------+-------+-------+---------------+---------------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+---------------+---------+------+------+-------------+
| 1 | SIMPLE | B | range | IXs_time_poly | IXs_time_poly | 32 | NULL | 1 | Using where |
+----+-------------+-------+-------+---------------+---------------+---------+------+------+-------------+
1 row in set (0.00 sec)
, inter.
, - .
,
-Dipin