Django admin edit page massive SQL slowdown with LEFT OUTER JOIN.

I was debugging why a particular page suddenly sent my postgresql process through the roof / eating a gig of memory before I shut it down.

I started debugging the SQL itself, and saw a LEFT OUTER JOIN. I was wondering where this magic was coming from…

It turns out the culprit was obvious: by default, a django admin ForeignKey field will list ALL objects in the referenced table. If that table is very large, it will pull all fields for every object there and consume your server.

Simply set the foreign key field in the readonly_fields to prevent this behavior.

Advertisements

One thought on “Django admin edit page massive SQL slowdown with LEFT OUTER JOIN.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s