Issues with Region Splitting in TiDB

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

Original topic: tidb的region分裂的的问题

| username: zhanggame1

[Test Environment for TiDB]
[Encountered Issue: Phenomenon and Impact]
Today during testing, I created a test table with two columns: a primary key int field and another bigint field. I then inserted 1 million rows into the table, with the primary key field ranging from 1 to 1 million and the other field all set to 0. Afterward, I used SHOW TABLE REGIONS and found that many regions were generated, but each had a very small amount of data. Does anyone know what might be happening? Will they automatically merge in the future?

| username: Kongdom | Original post link

I suggest posting the table creation statement. You didn’t use a random primary key, did you?

| username: zhanggame1 | Original post link

It’s neither a random primary key nor an auto-increment.

| username: zhanggame1 | Original post link

After waiting for a while, the regions indeed merged by themselves. This is the situation after the automatic merge: 27 regions have merged into 14.

| username: redgame | Original post link

Automatically merged.

| username: Kongdom | Original post link

:thinking:
High EQ: Automatically scatter to avoid hotspots
Low EQ: There might be a problem here
:rofl:

| username: zhanggame1 | Original post link

Then I tested a few more times, but couldn’t reproduce the issue. All the data, 1 million records, fit into a single region.

| username: Kongdom | Original post link

:thinking: Then I have reason to suspect that the first time a random primary key was used.

| username: h5n1 | Original post link

Is inserting 1 million records considered a single transaction? When there is a large transaction that reaches a certain threshold, TiDB will pre-split the region. You can see related information in the tidb.log.

| username: zhanggame1 | Original post link

It is a transaction, inserted all at once.

| username: h5n1 | Original post link

That means the system automatically pre-splits the regions. Test it again and check tidb.log.

| username: zhanggame1 | Original post link

However, it cannot be reproduced.

| username: h5n1 | Original post link

Was the table rebuilt?

| username: zhanggame1 | Original post link

truncate’s

| username: knull | Original post link

What are your approximate steps? What is the table structure?

Additionally, is the truncate operation being tested repeatedly, or did you find many regions after truncating and then inserting for the first time?

| username: system | Original post link

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