I was reading this article, which talks about storing location-based information. The author says that while Latitude and Longitude info for the locations can be stored in a SQL database, retrieving and searching through that information using SQL queries can be expensive, even with Latitude and Longitude mapped to their own indexes in the DB. So far so good.
To address this, the author divides the map into a 4 block grid, where each block is further divided into more blocks in such a fashion that each block contains some threshold number of locations. This is represented via a Quadtree
. This will indeed make the search simpler, but what I am not clear is a couple of things:
- Is the grid i.e.
Quadtree
a separate table in the SQL database, or is it simply a data-structure in the application-servers memory? (Given the grid is used in the sample query that the author shows later, perhaps it's a table in the same SQL database?:
Select * from Places where Latitude between X-D and X+D and Longitude
between Y-D and Y+D and GridID in (GridID, GridID1, GridID2, …, GridID8)
- If so, then how can a Quadtree be stored as a SQL table? Or is it not a table but a type of index that databases use (eg. B-Trees). But then how is it included in the query?
- If neither, then where exactly is Quadtree used in this system design?
- A little different question, one way the Quadtrees can be represented is using
Hilbert Curves
. Where does this fit into the picture?