DROP TABLE IF EXISTS shops;
CREATE TABLE shops (
id INT PRIMARY KEY AUTO_INCREMENT,
name TEXT,
location GEOMETRY NOT NULL,
SPATIAL KEY location_index (location)
);
INSERT INTO shops (name, location)
VALUES ('nezu-no-taiyaki',
ST_GeomFromText('POINT(35.720253 139.762573)'));
INSERT INTO shops (name, location)
VALUES ('taiyaki-kataoka',
ST_GeomFromText('POINT(35.712521 139.715591)'));
INSERT INTO shops (name, location)
VALUES ('soba-taiyaki-ku',
ST_GeomFromText('POINT(35.683712 139.659088)'));
INSERT INTO shops (name, location)
VALUES ('kuruma',
ST_GeomFromText('POINT(35.721516 139.706207)'));
INSERT INTO shops (name, location)
VALUES ('hirose-ya',
ST_GeomFromText('POINT(35.714844 139.685608)'));
INSERT INTO shops (name, location)
VALUES ('sazare',
ST_GeomFromText('POINT(35.714653 139.685043)'));
INSERT INTO shops (name, location)
VALUES ('omede-taiyaki',
ST_GeomFromText('POINT(35.700516 139.817154)'));
INSERT INTO shops (name, location)
VALUES ('onaga-ya',
ST_GeomFromText('POINT(35.698254 139.81105)'));
INSERT INTO shops (name, location)
VALUES ('shiro-ya',
ST_GeomFromText('POINT(35.705517 139.638611)'));
INSERT INTO shops (name, location)
VALUES ('fuji-ya',
ST_GeomFromText('POINT(35.703938 139.637115)'));
INSERT INTO shops (name, location)
VALUES ('miyoshi',
ST_GeomFromText('POINT(35.644539 139.537323)'));
INSERT INTO shops (name, location)
VALUES ('juju-ya',
ST_GeomFromText('POINT(35.628922 139.695755)'));
INSERT INTO shops (name, location)
VALUES ('tatsumi-ya',
ST_GeomFromText('POINT(35.665501 139.638657)'));
INSERT INTO shops (name, location)
VALUES ('tetsuji',
ST_GeomFromText('POINT(35.680912 139.76857)'));
INSERT INTO shops (name, location)
VALUES ('gazuma-ya',
ST_GeomFromText('POINT(35.700817 139.647598)'));
INSERT INTO shops (name, location)
VALUES ('honma-mon',
ST_GeomFromText('POINT(35.722736 139.652573)'));
INSERT INTO shops (name, location)
VALUES ('naniwa-ya',
ST_GeomFromText('POINT(35.730061 139.796234)'));
INSERT INTO shops (name, location)
VALUES ('kuro-dai',
ST_GeomFromText('POINT(35.650345 139.704834)'));
INSERT INTO shops (name, location)
VALUES ('daruma',
ST_GeomFromText('POINT(35.681461 139.770599)'));
INSERT INTO shops (name, location)
VALUES ('yanagi-ya',
ST_GeomFromText('POINT(35.685341 139.783981)'));
INSERT INTO shops (name, location)
VALUES ('sharaku',
ST_GeomFromText('POINT(35.716969 139.794846)'));
INSERT INTO shops (name, location)
VALUES ('takane',
ST_GeomFromText('POINT(35.698601 139.560913)'));
INSERT INTO shops (name, location)
VALUES ('chiyoda',
ST_GeomFromText('POINT(35.642601 139.652817)'));
INSERT INTO shops (name, location)
VALUES ('da-ka-po',
ST_GeomFromText('POINT(35.627346 139.727356)'));
INSERT INTO shops (name, location)
VALUES ('matsushima-ya',
ST_GeomFromText('POINT(35.640556 139.737381)'));
INSERT INTO shops (name, location)
VALUES ('kazuya',
ST_GeomFromText('POINT(35.673508 139.760895)'));
INSERT INTO shops (name, location)
VALUES ('furuya-kogane-an',
ST_GeomFromText('POINT(35.680603 139.676071)'));
INSERT INTO shops (name, location)
VALUES ('hachi-no-ie',
ST_GeomFromText('POINT(35.608021 139.668106)'));
INSERT INTO shops (name, location)
VALUES ('azuki-chan',
ST_GeomFromText('POINT(35.64151 139.673203)'));
INSERT INTO shops (name, location)
VALUES ('kuriko-an',
ST_GeomFromText('POINT(35.712013 139.796829)'));
INSERT INTO shops (name, location)
VALUES ('yume-no-aru-machi-no-taiyaki-ya-san',
ST_GeomFromText('POINT(35.616199 139.712524)'));
INSERT INTO shops (name, location)
VALUES ('naze-ya',
ST_GeomFromText('POINT(35.609039 139.665833)'));
INSERT INTO shops (name, location)
VALUES ('sanoki-ya',
ST_GeomFromText('POINT(35.66592 139.770721)'));
INSERT INTO shops (name, location)
VALUES ('shigeta',
ST_GeomFromText('POINT(35.672626 139.780273)'));
INSERT INTO shops (name, location)
VALUES ('nishimi-ya',
ST_GeomFromText('POINT(35.671825 139.774628)'));
INSERT INTO shops (name, location)
VALUES ('hiiragi',
ST_GeomFromText('POINT(35.647701 139.711517)'));
SELECT id, name, ST_AsText(location) AS location_text FROM shops;
id	name	location_text
1	nezu-no-taiyaki	POINT(35.72025305555556 139.76257305555555)
2	taiyaki-kataoka	POINT(35.712521111111116 139.7155911111111)
3	soba-taiyaki-ku	POINT(35.68371194444445 139.65908805555557)
4	kuruma	POINT(35.72151611111111 139.70620694444446)
5	hirose-ya	POINT(35.71484388888889 139.68560805555555)
6	sazare	POINT(35.71465305555556 139.68504305555555)
7	omede-taiyaki	POINT(35.70051611111111 139.8171538888889)
8	onaga-ya	POINT(35.69825388888889 139.81105)
9	shiro-ya	POINT(35.70551694444445 139.63861111111112)
10	fuji-ya	POINT(35.703938055555554 139.637115)
11	miyoshi	POINT(35.644538888888896 139.53732305555556)
12	juju-ya	POINT(35.62892194444445 139.69575500000002)
13	tatsumi-ya	POINT(35.66550111111111 139.63865694444445)
14	tetsuji	POINT(35.680911944444446 139.76857)
15	gazuma-ya	POINT(35.70081694444444 139.64759805555553)
16	honma-mon	POINT(35.72273611111111 139.65257305555556)
17	naniwa-ya	POINT(35.73006111111111 139.79623388888888)
18	kuro-dai	POINT(35.650345 139.70483388888888)
19	daruma	POINT(35.68146111111111 139.7705988888889)
20	yanagi-ya	POINT(35.685341111111114 139.78398111111113)
21	sharaku	POINT(35.71696888888889 139.79484611111113)
22	takane	POINT(35.69860111111112 139.56091305555555)
23	chiyoda	POINT(35.64260111111111 139.65281694444442)
24	da-ka-po	POINT(35.62734611111111 139.72735611111113)
25	matsushima-ya	POINT(35.64055611111111 139.73738111111112)
26	kazuya	POINT(35.67350805555556 139.760895)
27	furuya-kogane-an	POINT(35.68060305555556 139.67607111111113)
28	hachi-no-ie	POINT(35.608021111111114 139.66810611111111)
29	azuki-chan	POINT(35.641510000000004 139.67320305555555)
30	kuriko-an	POINT(35.71201305555556 139.79682888888888)
31	yume-no-aru-machi-no-taiyaki-ya-san	POINT(35.61619888888889 139.71252388888888)
32	naze-ya	POINT(35.60903888888889 139.66583305555557)
33	sanoki-ya	POINT(35.66592 139.7707211111111)
34	shigeta	POINT(35.67262611111111 139.78027305555557)
35	nishimi-ya	POINT(35.671825 139.77462805555555)
36	hiiragi	POINT(35.64770111111111 139.71151694444444)
SELECT id, name, ST_AsText(location) AS location_text FROM shops
WHERE MBRContains(ST_GeomFromText('LineString(35.6684 139.7727, 35.7121 139.7038)'), location)
ORDER BY id;
id	name	location_text
14	tetsuji	POINT(35.680911944444446 139.76857)
19	daruma	POINT(35.68146111111111 139.7705988888889)
26	kazuya	POINT(35.67350805555556 139.760895)
EXPLAIN
SELECT id, name, ST_AsText(location) AS location_text FROM shops
WHERE MBRContains(ST_GeomFromText('LineString(35.6684 139.7727, 35.7121 139.7038)'), location)
ORDER BY id;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	shops	range	location_index	location_index	34	NULL	36	Using where; Using filesort
DROP TABLE shops;
