In TiDB, if it is a non-clustered table and the primary key is an integer, is the primary key still used as the rowid?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 请问tidb中如果为 非 聚簇表,并且主键是整型的,那么这个时候还是用主键做rowid?

| username: liuwenhe

【TiDB Environment】Production
【TiDB Version】tidb 5.1
【Encountered Problem】
【Reproduction Path】What operations were performed to cause the problem
【Problem Phenomenon and Impact】
I have a question about the principle,

  1. In TiDB, if the table is non-clustered and the primary key is an integer, is the primary key still used as the rowid in this case?
  2. If the table in TiDB is clustered but the primary key is non-integer, is the primary key still used as the rowid in this case?
| username: OnTheRoad | Original post link

aa: “The TiDB cluster is composed of multiple components, including PD (Placement Driver), TiKV (Key-Value storage engine), and TiDB (SQL layer). Each component can be scaled independently to meet different workload requirements.”

bb: “In a TiDB cluster, PD is responsible for storing the metadata of the cluster, managing the distribution of data, and scheduling the load balancing. TiKV is the distributed storage engine that stores the actual data, and TiDB is the SQL layer that processes SQL queries and interacts with the underlying storage.”

| username: h5n1 | Original post link

The primary key is a separate index, and the rowid is automatically assigned by the system.
You can query MVCC information via curl http://{TiDBIP}:10080/mvcc/key/{db}/{table}/rowid.

A clustered table with a non-integer primary key uses the primary key column as part of the key, and there is no rowid.
You can query MVCC information via curl http://{TiDBIP}:10080/mvcc/key/{db}/{table}?${c1}=${v1}&${c2}=${v2}.

| username: forever | Original post link

If it is a non-clustered table, an internally implicitly allocated rowid will be used regardless of whether the primary key is an integer or not; the primary key is just a unique index.
If it is a clustered table, the primary key will be used as the rowid (more precisely, the key) regardless of whether the primary key is an integer or not. If there is no primary key, an internally generated rowid will be used as the key.

| username: liuwenhe | Original post link

If it is a non-clustered table, an internally implicitly allocated rowid will be used regardless of whether the primary key is an integer, and the primary key is just a unique index.
If it is a clustered table, the primary key will be used as the rowid (more precisely, the key) regardless of whether the primary key is an integer. If there is no primary key, an internally generated rowid will be used as the key.

The key is tableid + rowid. How should we understand “more precisely, the key” as you mentioned?

| username: xiaohetao | Original post link

For non-clustered tables, the primary key is the index, and the rowid is automatically generated by the system.

| username: forever | Original post link

To be precise, a primary key is a primary key, and a rowid is an implicitly generated rowid. There is no necessary connection between the two. They both serve to generate keys and indicate how the table organizes data. For example, if a clustered table has a primary key, it will organize data based on the primary key, and the key will be tableid + primary key.

| username: liuwenhe | Original post link

The key is tableid+pk (clustered table) or tableid+rowid (non-clustered table), which makes it clearer.

| username: forever | Original post link

You can check out TiDB’s official courses, they explain these conceptual things in great detail. :grin:

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.