Django Cluster Index

My models have two tables:

1) Owner:

OwnerName 

2) Car

 OwnerKey CarName CarPrice 

Here, when creating a row in the Owner table, I also add Cars for this owner of the Car table. Thus, all cars for a specific owner are stored sequentially in the car table. Now, if I want to ask, should I use cluster indexing or not? As soon as cars for a specific owner are saved, no cars will be added for this owner, no cars will be deleted, only the price will be changed. What to do for quick access? And how to implement cluster index through django?

+7
database django mysql django-models clustered-index
source share
1 answer

You are asking about querying for information that requires learning SQL, not just Django code.

If you have only a thousand owners and cars, everything will be fast enough. If you have a million owners or cars, you need indexes, not necessarily "grouped."

The "clustered" key is implemented in MySQL as a PRIMARY KEY . You can have only one table, and its values ​​must be unique.

I Django, do something like this to get PK:

 column1 = models.IntegerField(primary_key = True) 

Please provide a table layout that you already have. That is, marry Django and get SHOW CREATE TABLE . (What you provided is too vague, so my answer is too vague.)

Literature:

There are no "clustered" indexes other than PRIMARY KEY . However, the secondary key may have similar performance if it is a “coverage index”. This term refers to an index that contains all the columns found in SELECT . In addition, the columns are ordered correctly.

Look at your SELECT for a better judge of what you need.

+1
source share

All Articles