简体   繁体   English

django的聚集指数

[英]Clustered index in django

I have two tables in my models: 我的模型中有两张桌子:

1)Owner: 1)拥有者:

OwnerName

2)Car 2)汽车

OwnerKey

CarName

CarPrice

Here while creating a row in Owner table, I also add the Cars for that owner Car table. 这里在Owner表中创建一行时,我还为该所有者Car table添加了Cars。 So all the cars for a particular owner are stored sequentially in the Car table.Now if I want to ask whether should I use cluster indexing or not? 因此,特定所有者的所有汽车都按顺序存储在Car表中。现在,如果我想询问是否应该使用集群索引? Once the cars for a particular owner are saved, no cars are then added for that owner neither any car is deleted, just the price is changed. 一旦保存了特定车主的车辆,则不会为该车主添加任何车辆,也不会删除任何车辆,只需更改价格。 What should I do for a faster access? 我应该怎样做才能加快访问速度? And how to implement cluster index via django? 以及如何通过django实现集群索引?

You question is asking for information that requires studying the SQL, not just the Django code. 您的问题是要求提供需要研究SQL的信息,而不仅仅是Django代码。

If you have only a thousand owners and cars, things will probably be fast enough. 如果你只有一千个车主和汽车,那么事情可能就足够快了。 If you have a million owners or cars, you need indexes, not necessarily "clustered". 如果你有一百万所有者或汽车,你需要索引,不一定是“集群”。

A "clustered" key is implemented in MySQL as a PRIMARY KEY . “群集”密钥在MySQL中实现为PRIMARY KEY You can have only one per table, and its values must be unique. 每个表只能有一个,其值必须是唯一的。

I Django, do something like this to get a PK: 我是Django,做这样的事来获得PK:

column1 = models.IntegerField(primary_key = True)

Please provide the table schema you already have. 请提供您已有的表格架构。 That is, go beyond Django and get SHOW CREATE TABLE . 也就是说,超越Django并获得SHOW CREATE TABLE (What you have provided is too vague; hence my answer is too vague.) (你提供的内容太模糊;因此我的答案太模糊了。)

References: 参考文献:

There are no "clustered" indexes other than the PRIMARY KEY . 除了PRIMARY KEY之外,没有“聚集”索引。 However, a secondary key can have similar performance if it is a "covering index". 但是,如果辅助密钥是“覆盖索引”, 它可以具有类似的性能。 That term refers to an index that contains all the columns that are found in the SELECT . 该术语指的是包含SELECT中找到的所有列的索引。 Also , the columns are ordered correctly. 此外 ,列正确排序。

Let's see your SELECT statements in order to better judge what is needed. 让我们看看你的SELECT语句,以便更好地判断需要什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM