Source: https://www.liaoxuefeng.com/wiki/1177760294764384
- Without using any field related to the service as a primary key
-
Without necessary, we try not to use the primary key, because it brings to the table a rise in complexity
- As the foreign key constraint will reduce the performance of the database, the majority of Internet applications for the pursuit of speed, does not set the foreign key constraint, but only by the application itself to ensure the correctness of the logic. In this case,
class_id
just a regular column, but it played a key role outside of it. - Many relationship is actually implemented by two-to-many relationship, that is, through an intermediate table, associated with two-many relationship to-many relationship is formed:
- There are some applications, a large table will split into two tables one object is to separate and often do not always read the read field, in order to obtain higher performance. For example, to split a large user table for the user basic information table
user_info
and user detailed information tableuser_profiles
, most of the time, only need to query theuser_info
table, you do not need to query theuser_profiles
table, so that you can improve query speed. - The index is a data structure in the relational database for pre-sorting a plurality of values of a row or column. By using the index, you can let the database system does not have to scan the entire table, but directly to locate records meet the criteria, thus greatly speeding up the query speed.
- Efficiency index depends on whether the hash value of the index column that the column value if the more different from each other, so the higher the efficiency index. Conversely, if there is a recording of a large number of columns of the same value, such as
gender
columns, about half of the recorded valuesM
, the other half isF
, therefore, create an index on that column does not make sense. You can create multiple indexes on a table. Advantage of the index is to improve query efficiency, the disadvantage is in insert, update and delete records time, you need to modify the index, so the more the index, insert, update, and delete records slower pace. For primary key, its relational database will automatically create a primary key index. Efficient use of the primary key index is the highest since the primary key will be the only absolute guarantee. -
Without
FROM
clauseSELECT
statement has a useful application, is used to determine the current connection to the database is valid. Many detection tool performs aSELECT 1;
test database connection. OFFSET
More than the maximum number of queries and does not complain, but to get an empty result set.In MySQL,
LIMIT 15 OFFSET 30
it can also be abbreviated asLIMIT 30, 15
.Use
LIMIT <M> OFFSET <N>
when paging, asN
more and more, the query efficiency will be lower and lower.- Aggregate query: SELECT COUNT (*) FROM students; packet aggregation: SELECT COUNT (*) num FROM students GROUP BY class_id;
-
-
-
- The multi-function statements as a whole to operate, is called a database transaction. Ensures that all database transactions can operate within the scope of a transaction can all succeed or all fail. If the transaction fails, then the effect would be without the implementation of these SQL, as there will be no changes to the database data.
-
- Dirty read (Dirty read)
- Phantom read:
-