I am working on an application that needs to run SQL queries to see whether certain locations fall into jurisdictions which are defined by polygons. These jurisdictions are updated quarterly, meaning I also need to check them against whatever date I'm checking it on. I'm using the mySQL function MBRContains
to help narrow down the jurisdictions I'm looking at, making it easier for my application to then check if the given point lands in any of them. Right now, my queries look like this:
SELECT DISTINCT t0.id FROM jurisdiction t0
WHERE t0.beginDate <= '2017-08-05' AND t0.endDate >= '2017-08-05'
AND MBRContains(t0.geometry,GeomFromText("POINT(48.0 -120.0)"));
I'm fairly sure that MBRContains is a more expensive operation than checking the date, but I haven't worked with SQL much and I'm unsure how to make it so the jurisdictions will be filtered by date first, then checked against MBRContains. How can I do this? Are there other optimizations I could do while achieving the same results with this query?