I have a table with (among others) x and y fields of SMALLINT type and pt of POINT type, set to POINT(x,y);
x and y have normal indecies and pt has a spatial index set.
Profiling typical query
select sql_no_cache
count(0) from `table_name`
where (x between -50 and 50)
and (y between -50 and 50);
-- vs
set @g = GeomFromText('Polygon((-50 -50, 50 -50, 50 50, -50 50, -50 -50))');
select sql_no_cache
count(0) from `table_name`
where MBRContains(@g, `pt`);
... shows that query via x and y is 1.5 times faster:
3.45±0.10ms vs 4.61±0.14ms over 10 queries.
x and y would always be INT and only rectangular (even square) areas would be queried. Yes, this is carved in stone ;-)
The main question is:
Have I missed something about indecies or is spatial data an overkill in such case?
- MySQL version is 5.1.37
- DB Engine type is MyISAM (default)
- Current table size is 5k rows, 10-30k planned in production.
I have had some experience with MySQL, but never worked with spatial data types and spatial indecies.