Adding a Primary Key to an Empty Table Causes a Hang

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

Original topic: 空表添加主键,卡死

| username: 大飞哥online

[TiDB Usage Environment] Test
[TiDB Version] 7.1.0
[Reproduction Path] First create a table without a primary key, then add a primary key
[Encountered Problem: Phenomenon and Impact] Adding a primary key causes a freeze
[Attachment: Screenshot/Log/Monitoring]

SQL to create an empty table:

CREATE TABLE `cft` (
  `id` bigint(20) NOT NULL,
  `balance` decimal(15,2) DEFAULT NULL,
  `nickname` varchar(100) DEFAULT NULL
);

Then add the primary key:

ALTER TABLE `cft` ADD PRIMARY KEY (id);

Check with show processlist, it freezes

How to troubleshoot this?

| username: 大飞哥online | Original post link

The TiDB logs keep showing the following:

| username: 大飞哥online | Original post link

There is no directory /tmp/tidb,
The tmp-storage-path parameter is /tmp/1000_tidb/MC4wLjAuMDo0MDAwLzAuMC4wLjA6MTAwODA=/tmp-storage
The temp-dir parameter is /tmp/tidb

Manually created /tmp/tidb and gave it 777 permissions, tidb:tidb, but still got an error.
Further created /tmp/tidb/tmp_ddl-4000 and changed ownership to tidb:tidb recursively, then DDL executed successfully.

Why wasn’t this file automatically created?

| username: zhanggame1 | Original post link

Was the tidb user created during the installation?

| username: 大飞哥online | Original post link

It was not created by myself; it was automatically created by the tiup cluster deployment environment.

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

We have encountered this issue as well. An upgraded cluster did not automatically create that directory. This directory is needed for the index acceleration feature and will generate some temporary files under it.

| username: 大飞哥online | Original post link

This needs to be optimized and worked on.

| username: cassblanca | Original post link

Here’s a bug report :smiley:

| username: redgame | Original post link

Insufficient resources?

| username: 有猫万事足 | Original post link

Some directory issues and file permission issues, I found are somewhat related to the operating system. When I deploy on Ubuntu, some directories cannot be found. There are no such problems on CentOS 7.

| username: zhanggame1 | Original post link

The default permissions for /tmp on both Ubuntu and CentOS 7 should be 777. It’s very strange if there are no permissions.

| username: 大飞哥online | Original post link

Where to mention it?

| username: 大飞哥online | Original post link

It’s sufficient, but there’s no automatic creation; you need to manually create the directory files.

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

The directory does not exist, and it did not automatically create the directory.

| username: system | Original post link

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