Conceptual differences:
Primary key: Refers to a column where the field is unique and is not a null value.
Primary key index: refers to the primary key, the primary key does not have a clear concept definition, the primary key is both a constraint, an index, a primary key is an index, is a unique index of the special type. when you create a primary key, the database creates a unique index by default for the primary key.
Self-increment primary key: The field type is numeric, self-increment, and is a primary key.
Unique index: The value of the indexed column must be unique, but a null value is allowed. The primary key is a unique index, so that's true. But the unique index is also the primary key for the anti-fire error, because the unique index allows null values, the primary key does not allow null values, so it cannot be said that the unique index is also the primary key.
Performance differences:
Through testing, the discovery of primary key, self-increment primary key, unique index query efficiency is not the same, of course, this gap is very small, summed up as:
Query: Unique index > Auto-increment primary key > Primary key (primary key index)
Insert: primary key > Auto-increment primary key > unique index
Test scenario:
Create 3 tables with the same name field: Id,name,money,traddate
Insert the same data for each 100W bar
Table A:id primary key, table B:id self-increment and primary key, Tablec:id create unique index
Inquire:
Performance: Unique index > Auto-increment primary key > Primary key (primary key index)
Table A (primary key): 0.06s
b Table (self-increasing primary key): 0.01s,
C table (unique index): 0.00s
Insert:
10W data, Bulk Insert, performance: primary key > Auto-increment primary key > unique index
Table A (primary key):38.408s
b Table (self-increasing primary key): 38.708s,
C table (unique index): 39.018s
Write so much, suddenly feel to do this test does not make any sense, have wood?
Primary key, self-increment primary key, primary key index, unique index concept difference and performance difference