Even if you use PostGIS, you do not need to use the ST_Buffer function, but ST_Expand , which performs an operation equivalent to this (pseudo-code):
-- expand bounding box with 'units' in each direction envelope.xmin -= units; envelope.ymin -= units; envelope.xmax += units; envelope.ymax += units; -- also Z coordinate can be expanded this way
In PostGIS syntax, an SQL query typically looks like this:
SELECT AsText(geom) FROM mypoints WHERE -- operator && triggers use of spatial index, for better performance geom && ST_Expand(ST_GeometryFromText('POINT(10 20)', 1234), 5) AND -- and here is the actual filter condition Distance(geom, ST_GeometryFromText('POINT(10 20)', 1234)) < 5
Find Buffer vs Expand the explanation on the postgis-users mailing list.
Thus, ideally, it would be to replicate similar behavior with MySQL. I'm not a MySQL expert at all, but I assume that this is possible even if there is no ST_Expand function.
Here's how to simulate the ST_Expand function:
CONCAT('POLYGON((', X(GeomFromText('POINT(10 20)')) - 5, ' ', Y(GeomFromText('POINT(10 20)')) - 5, ',', X(GeomFromText('POINT(10 20)')) + 5, ' ', Y(GeomFromText('POINT(10 20)')) - 5, ',', X(GeomFromText('POINT(10 20)')) + 5, ' ', Y(GeomFromText('POINT(10 20)')) + 5, ',', X(GeomFromText('POINT(10 20)')) - 5, ' ', Y(GeomFromText('POINT(10 20)')) + 5, ',', X(GeomFromText('POINT(10 20)')) - 5, ' ', Y(GeomFromText('POINT(10 20)')) - 5, '))' );
Then combine this result with the query as follows:
SELECT AsText(geom) FROM mypoints WHERE -- AFAIK, this should trigger use of spatial index in MySQL -- replace XXX with the of expanded point as result of CONCAT above Intersects(geom, GeomFromText( XXX ) ) AND -- test condition Distance(geom, GeomFromText('POINT(10 20)')) < 5
If you work with older versions of MySQL where the distance function is not available, you can simply use the amercader method to calculate based on SQRT.
Hope this gives you some idea.