For at optimere indlejrede sæt-forespørgsler i MySQL
, bør du oprette en SPATIAL
(R-Tree
) indeks på de indstillede felter:
ALTER TABLE projects ADD sets LINESTRING;
UPDATE projects
SET sets = LineString(Point(-1, lft), Point(1, rgt));
ALTER TABLE projects MODIFY sets LINESTRING NOT NULL;
CREATE SPATIAL INDEX sx_projects_sets ON projects (sets);
SELECT hp.*
FROM projects hp
WHERE MBRWithin(Point(0, 4), hp.sets)
ORDER BY
lft;
Se denne artikel i min blog for flere detaljer: