# Clustered and Non-Clustered Indexes for Primary Keys Summary
![`smart`](ClusteredVsNonClusteredTable_en_003_20231114.png)
------------------------------------------------------------------------------
In a clustered index for primary key scenario, the primary key of the table is the same as the key of the mapped key-value pair in the TiKV map. There is a one-to-one correspondence between the rows in the TiDB table and the key-value pair entries in TiKV store.
- The TiKV `KV` entry comprises the following `key` and `value`:
  - The key is the primary key with the table `ID` prefix.
  - The value comes from the other columns except the primary key.

For non-clustered index for primary key, each row is represented by two `key-value` pair entries in TiKV. 
- The TiKV `KV` entries comprise the following `key` and `value` pairs:
  - The index record key is the primary key value with the index `ID` prefix.
  - The index record value is the hidden primary key column `_tidb_rowid`.
  - The table row record key is the hidden primary key column `_tidb_rowid` with the table `ID` prefix.
  - The table row value consists all columns of the row.

For non-clustered index for hidden primary key, each row also maps to a single `key-value` pair entry in TiKV. TiDB generates a hidden primary key column named `_tidb_rowid` in this scenario. To create a table with a non-clustered hidden primary key, you can simply create a table without specifying a primary key as shown in the slide.
- The TiKV `KV` entry comprises the following `key` and `value`:
  - The key is the hidden primary key column `_tidb_rowid` with the table `ID` prefix.
  - The value consists all columns of the row.

Based on the comparison of read `(SELECT)` and write `(INSERT / UPDATE / DELETE)` operations between the clustered index and non-clustered index, you can conclude that generally when a table includes a primary key column and requires frequent data access (query or modifications) based on the primary key, it is optimal to design it as a table with clustered index for primary key as possible, it saves storage space and reduces IO operations compared to a table with non-clustered index for primary key. 

For the sake of conciseness, we can refer to the table with a clustered index on the primary key as a "clustered index table", the table with a non-clustered index on the primary key as a "non-clustered index table", and the table with a non-clustered index on a hidden primary key as an "implicit primary key table". And, please remember that an implicit primary key table belongs to the non-clustered index type.

