English 中文(简体)
这是否加速了Django 外凯的检查?
原标题:Would this trick speed up Django ForeignKey lookup?
  • 时间:2012-01-14 21:21:09
  •  标签:
  • django

我正试图加快我的Django申请。 我注意到的一个问题是,对外国关键关系进行的反向调查似乎并不有效。

例如,设想教师能够有许多学生,但学生只能有一位教师。 我们可以向每个学生与教师挂钩的学生分配外凯。 在学生表中,一栏名为teacher_id。 跟踪一名学生的教师。

在询问学生拥有X的教师时,必须扫描所有学生桌子,以获得似乎效率不高的整套询问。

如果我计划“Django”,每当教师被分配到学生时,就可更新教师名册上的条目,如<代码>student_id_list<>;学生的身份证将附在一份其他学生身份证的混合清单中。

这样一来,当问询涉及教师的所有学生时,我就只能利用这个按ma分列的学生身份证清单来寻找学生,这很快(ID是首要的关键),而且效率高(并非学生桌上的每一行都必须扫描)。

学生表中的教师栏目仍然使用;数据只储存两次。

这是否使我的申请更快? 感谢!

最佳回答

根据我的理解,你想要为最佳查询业绩而选择数据库计划。 在这种情况下,我可以建议你为此目的专门设计的申请:django-composition

正如文件所说:

django-composition provides the abstract way to denormalize data from your models in simple declarative way through special generic model field called CompositionField.

Most cases of data denormalization are pretty common so django-composition has several "short-cuts" fields that handles most of them.

CompositionField is django model field that provides interface to data denormalization.

问题回答

我不敢肯定,但看起来错。 给每个学生发放一些身份证,即N级学校,N级学校是教师的一些学生,而你可以由教师对学生进行过滤,这是对全体学生的唯一追求。
可以依靠非银的指数,但与“学生选修课程......”相同。

不要试图在数据库上打上数据库层的附加元数据,为什么在贵国数据库中不设置适当的指数,或者如果该指数有助于使用某种观点或储存程序组合,并利用一种原始的 s子来援引该数据?





相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...