Home > Enterprise >  PostgreSQL VS MySQL while dealing with GeoDjango in Django
PostgreSQL VS MySQL while dealing with GeoDjango in Django

Time:10-19

There are multiple Tutorials/Questions over the Internet/Youtube/StackOverflow for finding nearyby businesses, given a location, for example (Question on StackOverflow) :

  • enter image description here

    Here a user can register as a customer as well as a business (customer's and business's name/address etc (all) fields will be separate, even if its the same user)

    • This is not how database is, only for rough idea or project

    1. Both customer and business will have their locations stored
    2. Customers can find nearby businesses around him

    I was wondering what are the specific advantages of using PostgreSQL over MySQL in context to computing and fetching the location related fields.
    (MySQL is a well tested database for years and most of my data is relational, so I was planning to use MySQL or Microsoft SQL Server)

    Would there be any processing disadvantages in context to algorithms used to compute nearby businesses if I choose to go with MySQL, how would it make my system slow?

    CodePudding user response:

    But one thing common in these all is that they all prefers PostgreSQL (instead of MySQL) for Django's Geodjango library

    The reason why they suggest using Postgres is that it has better support for spatial data. It's not that MySQL doesn't support spatial data. However, there is a long list of features which Postgres supports and MySQL doesn't. You can look at this page for details. Almost every time MySQL is mentioned on that page, it is to describe a feature that it does not support, but that Postgres does.

    (MySQL is a well tested database for years and most of my data is relational, so I was planning to use MySQL or Microsoft SQL Server)

    Note that foriegn key constraints are not compatible with MyISAM, which is the only MySQL database engine which supports spatial indexes. So if you pick MySQL, you need to choose between referential integrity and fast spatial lookups.

    If you use Postgres, you can have both referential integrity and fast spatial lookups. Postgres is also a quite mature and widely used relational database these days.

    Would there be any processing disadvantages in context to algorithms used to compute nearby businesses if I choose to go with MySQL, how would it make my system slow?

    It really depends on how many businesses you're searching for. If you pick an engine that does not support spatial indexes, MySQL is forced to do a full table scan, which takes O(N) time. On the other hand, it can do bounding box comparisons to eliminate many geometries quite quickly. I have seen acceptable interactive performance for 100k points, with performance dropping off after that. In contrast, Postgres with a spatial index is fast for any number of points.

  • Related