Which region should be selected to insert a record in TiDB?

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

Original topic: tidb中insert一条记录要选择哪个region进行插入?

| username: lindoubled

As the topic suggests: If a table has many regions, then when inserting a piece of data, which region will it choose for insertion? If the table has an index, then which region will the same index record choose for insertion?

Is it based on the unique key to find the corresponding region?

| username: 我是咖啡哥 | Original post link

My understanding is that it is determined based on your key. If your primary key is auto-incremented, then it is basically the latest region. If it is random, then it depends on which region the converted key is in.

| username: h5n1 | Original post link

A region is a logical space divided based on key ranges, with the range being a left-open, right-closed interval. The size of a region is limited; it will split if it exceeds the maximum size and merge if the data is too small, causing changes in the key range of the region. The key format is as follows:

Each row of data in a table is encoded into (Key, Value) pairs according to the following rules:
Key: tablePrefix{TableID}_recordPrefixSep{RowID}
e.g., t1_r1
Value: [col1, col2, col3, col4]

For primary keys and unique indexes, the corresponding RowID needs to be quickly located based on the key value. Therefore, they are encoded into (Key, Value) pairs as follows:
Key: tablePrefix{tableID}_indexPrefixSep{indexID}_indexedColumnsValue e.g., t1_i1_key
Value: RowID

For ordinary secondary indexes, a key value may correspond to multiple rows, requiring a query of the corresponding RowID based on the key range:
Key: tablePrefix{TableID}_indexPrefixSep{IndexID}indexedColumnsValue{RowID}
e.g., t1_i1_key_rowid
Value: null

| username: lindoubled | Original post link

Thank you, thank you.

| username: system | Original post link

This topic was automatically closed 1 minute after the last reply. No new replies are allowed.