ClickHouse / ClickHouse/ClickHouse

UNDROP TABLE issue when using DROP DATABASE even if the database is re-created before UNDROP TABLE

Open
#87,870 1 comment 0 reactions 0 assignees View on GitHub
comp-database-engines external potential bug
Dominant language
C++
Stars
49.9k
Forks
9k
Avg merge
21h 32m
Merged PRs (30d)
515

Description

### Company or project name

Altinity Inc.
Database Support Engineer

### Describe what's wrong

When trying to undrop a table after `DROP DATABASE`, it will fail even after re-creating the database because the database directory hasn't yet been created.

### Does it reproduce on the most recent release?

Yes

### How to reproduce

Steps to reproduce:

```
CREATE DATABASE IF NOT EXISTS testdrop;

CREATE TABLE IF NOT EXISTS testdrop.t1
(
id UInt64,
col1 String,
col2 UInt32,
col3 Float64
)
ENGINE = MergeTree()
ORDER BY id;

INSERT INTO testdrop.t1
SELECT
number AS id,
concat('str_', toString(number)) AS col1,
number % 1000 AS col2,
rand64() / 1000000.0 AS col3
FROM numbers(10000000);

DROP DATABASE testdrop;

SELECT
concat('UNDROP TABLE ', database, '.', table, ';') AS undrop_stmt
FROM system.dropped_tables
WHERE database LIKE '%'
ORDER BY table_dropped_time DESC format TSVRaw

CREATE DATABASE IF NOT EXISTS testdrop;

UNDROP TABLE testdrop.t1;
```

Then error as shown above.

### Expected behavior

Undrop table should work as long as the dropped database is created, but doesn't.

The workaround is to do the following:

```
CREATE DATABASE IF NOT EXISTS testdrop

CREATE TABLE testdrop.dummy_table_to_initialize_db_folder
ENGINE = Log AS SELECT * FROM system.one

```

Then:

`UNDROP TABLE testdrop.t1;`

Succeeds.

### Error message and/or stacktrace

Error:

```Code: 521. DB::ErrnoException: Paths cannot be exchanged because /var/lib/clickhouse/metadata_dropped/t1.ebd32848-4836-411e-8d19-5c7f3d673c93.sql or /var/lib/clickhouse/store/8ea/8ea139fc-9982-45d0-8672-2e9057734171/t1.sql does not exist: , errno: 2, strerror: No such file or directory. (ATOMIC_RENAME_FAIL) (version 25.3.6.10034.altinitystable (altinity build))```

### Additional context

Testing UNDROP TABLE for a demo and discovered this.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.