Does a primary key speed up an index?

Besides the convenient auto-increment and UNIQUE functions, does the PC really speed up the index?

Will the speed be the same, regardless of whether it is indexed by non-PKed INT or PKed (same column, two different tests)? If I had the same column in the same table on the same system, would it be faster if the UNIQUE INT column with index is also included PK? PK makes an index that it coexists faster?

Please, actual results only with system statistics, if you can be so kind.

+6
source share
2 answers

the primary key for the table is the column or set of columns that you use in the most important vital queries . It has a linked index for fast query performance . Query performance depends on NOT NULL optimization , because it cannot contain NULL values. With the InnoDB storage system, table data is physically organized to perform ultrafast searches and sorted based on the column or columns of the primary key.

If your table is large and important, but does not have an explicit column or set of columns to use as the primary key, you can create a separate column with auto-increment values ​​that will be used as the primary key . These unique identifiers can serve as pointers to the corresponding rows in other tables when joining tables using foreign keys.

Also indicate the following places: http://www.dbasquare.com/2012/04/04/how-important-a-primary-key-can-be-for-mysql-performance/ and http: //www.w3schools. com / sql / sql_primarykey.asp

+11
source

Rows in the base table are uniquely identified by the primary key value defined for the table. The primary key for a table consists of the values ​​of one or more columns.

Primary keys are automatically indexed to facilitate efficient information retrieval.

The primary key index is the most efficient way to access the table.

Other columns or column combinations can be defined as a secondary index to improve data retrieval performance. Secondary indexes are defined in the table after its creation (using the CREATE INDEX statement).

An example of when a secondary index can be useful is that a search is performed regularly in a column without a key in a table with many rows, defining an index in a column can speed up the search. The search index does not affect the search result, but the search speed is optimized.

It should be noted, however, that indexes create overhead for update, delete, and insert operations, since the index must also be updated.

Indexes are internal structures that the user cannot explicitly obtain after creation. The index will be used if the process of optimizing internal queries determines it, which will increase the efficiency of the search.

SQL queries are automatically optimized when they are internally prepared for execution. The optimization process determines the most efficient way to complete each request, which may or may not include the use of an applicable index.

+3
source

All Articles