Reply To: Optimising complex queries: piggyback in-built or write from scratch
I agree with @shanebp.
If you go with this technique, it’s likely that the scaling bottleneck in the future will be your distance queries against the xprofile_data table. From what I’m guessing, you’re (a) having MySQL cast the string values in that table to floats so that you can do radius math on them, and (b) possibly joining the table against itself to get lat + long. In the future, you might consider creating a custom table for this purpose, which would either replace or mirror the storage of lat/long in the xprofile_data table. Then, do your distance queries against that custom table.
But yeah, what @shanebp said 🙂 Definitely do two queries, and cache the heck out of that first one, if possible.