[Fixed]-Django – PostgreSQL ForeignKeyField and ManyToManyField performance

1👍

Is this information accurate?

Probably.

I don’t have a big picture of just how significant or insignificant this performance impact is in practice…

Well there is your first problem, as the saying goes premature optimization is the root of all evil. Until you’ve completely profiled your system, its hard to say what if any impact optimising away Foreign Keys would do.

For example, consider a query that spends 1ms querying the database but 1 second performing other operations before delivering the content to the user after another second.

According to that article you linked, after some time, your query could be 95% slower, and run in nearly 2ms.

Which means you would optimise to save 1ms in a 2 second action, ultimately saving 0.001% of the effort.

Until you have thoroughly profiled your app and have determined that the time for foreign keys in the database is your most critical time loss, don’t worry because the time to rewrite the Django DB abstraction layer, and the time saved if your data gets out of sync will probably orders of magnitude more than you saved.

Leave a comment