There is a problem with the way mysql5.7 builds the index.

mysql version 5.7

question 1:
add an index to a field of numeric type: if the date is stored as int, can you add an index to the date in such a way as
index or key?
index (field name)?

question 2: whether to use index or key to index the plastic type? it"s so vague. I don"t know how to ask for advice.

question 3: if the middle table (name is C) in many-to-many, such as id Aid Bid, where Aid and Bid are associated table ID fields, should I add
index (Aid)
Index (Bid)
to improve query efficiency?

Mar.28,2021

. Not very clear, probably guess, when you say index refers to the general index, key refers to the primary key index? Because the index can be divided into field index and combined index from the number of fields (an index formed by multiple fields, multi-level relationship), and from the index type into general index, unique index, primary key index and full-text index. Based on the fact that you don't know much about the index (personal judgment), I will give you the following answer:

Index efficiency is determined by the repeatability of the index, for example, the field aid is a unique value, even if you do not set a unique index, it is actually equivalent to a unique index, and the index type of primary key index is the most efficient, but it can only set one, so it is generally used as a lookup identity. If you want to index a relational table, it would be nice to set two, one of which sets the table's identity field ID. Then another index creates an associated index AID,BID, it should be noted that according to your project requirements, the order of setting AID and BID needs to be adjusted, as for more, I do not think this table is needed, because the use of the index, it will only use one at a time. Please find out by yourself for more information.


index or key are just the names of the index. Depending on the demand, you can add a unique index to the required table. For intermediate tables, like the two indexes you add, it actually has an impact on query speed, but the data is unstable and can be solved by adding foreign keys in many-to-many tables. Finally, the indexed key pays attention to the length of the key to understand the concept of clustering.


I'm afraid you don't understand what an index is at all. The index has several indexes such as unique,primary key, key, fulltext, spatial, and then you can name it. And when you join multiple tables, it's not good to build an index individually, but it's your own use of this field, or how often you use it, to set up the index

.
Menu