【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,
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?
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?
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.”
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}.
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.
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?
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.