Friday, 15 June 2012

postgresql - Django: is using a ForeignKey likely to affect read performance on a big db? -


I have a large postgraduate database (approximately 500m rows, total 150 GB). This figure is relatively stable (only once Updated in the quarter), I want to optimize it for reading, not written.

Currently I have the following database structure using a foreign key:

  class practice (model. Model): code = models.IntegerField () name = models .CharField (Max_length = 200) Class Prescription (Model. Model): Practice = Model. Frequing (practice) project_action = model.feedfield (max_long = 15)  

If I often want to question this way, the big dataset is returning:

 < Code> p = practice.objects.filter (code = 1234) prescription = prescription.obays.filter (practice = P)  

will it be more efficient to reconstruct the database So that it does not have a foreign key:

  class prescription (model. Model): practice_id = models.IntegerField () presentation_ Code = models.CharField (max_length = 15)  

And then what to do in this view?

  p = practice.objects.filter (code = 1234) prescriptions = prescription. Filter (pract_id = 1234)  

I understand that if I do this, I run the risk of making orphan stories in data import - this is not a problem. I'm more interested in ensuring that the database runs faster and can cope with many users.

I currently have the first setup, and the Django-debug-toolbar shows that the visual query looks like this:

  from SELECT COUNT (*) "Frontend_prescription" WHERE "Frontend_prescription". "Chemical_id" = '0212000AA';  

Looking at this, maybe we can guess that changing the database structure will not speed up the questions read?

I understand that I can test my database by restructuring and test execution time, but with enough 500M rows, which is quite a lot :)

IntegerField ;

Excessive compulsion will not affect single-table reading performance, although using joins They affect the performance impact (positive), ie select_related .


No comments:

Post a Comment