Skip to content

Always use default database when creating distributed table #37318

@zouyonghao

Description

@zouyonghao

Describe the unexpected behaviour
Always use default database when creating distributed table

How to reproduce

  • Which ClickHouse server version to use
    22.4.5.9

The following statements fail with exceptions:

create database test on cluster test_cluster;

use test;

create table local_t_l5ydey on cluster test_cluster ( 
c_qv5rv INTEGER ,
c_rutjs4 INTEGER ,
c_wmj INTEGER ,
c_m3 TEXT NOT NULL,
primary key(c_qv5rv)
)
engine=ReplicatedMergeTree('/clickhouse/tables/test/{shard}/local_t_l5ydey', '{replica}');

create table t_l5ydey on cluster test_cluster as local_t_l5ydey
engine=Distributed('test_cluster','test','local_t_l5ydey', rand())
Query id: c0de0142-df6f-4703-9a68-9a491263133d

┌─host──────┬─port─┬─status─┬─error────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬─num_hosts_remaining─┬─num_hosts_active─┐
│ 127.0.0.1 │ 5000 │     60 │ Code: 60. DB::Exception: Table default.local_t_l5ydey doesn't exist. (UNKNOWN_TABLE) (version 22.4.5.9 (official build)) │                   3 │                0 │
│ 127.0.0.1 │ 5001 │     60 │ Code: 60. DB::Exception: Table default.local_t_l5ydey doesn't exist. (UNKNOWN_TABLE) (version 22.4.5.9 (official build)) │                   2 │                0 │
│ 127.0.0.1 │ 5002 │     60 │ Code: 60. DB::Exception: Table default.local_t_l5ydey doesn't exist. (UNKNOWN_TABLE) (version 22.4.5.9 (official build)) │                   1 │                0 │
│ 127.0.0.1 │ 5003 │     60 │ Code: 60. DB::Exception: Table default.local_t_l5ydey doesn't exist. (UNKNOWN_TABLE) (version 22.4.5.9 (official build)) │                   0 │                0 │
└───────────┴──────┴────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴─────────────────────┴──────────────────┘
→ Progress: 0.00 rows, 0.00 B (0.00 rows/s., 0.00 B/s.)  0%
4 rows in set. Elapsed: 0.173 sec. 

Received exception from server (version 22.4.5):
Code: 60. DB::Exception: Received from localhost:5000. DB::Exception: There was an error on [127.0.0.1:5000]: Code: 60. DB::Exception: Table default.local_t_l5ydey doesn't exist. (UNKNOWN_TABLE) (version 22.4.5.9 (official build)). (UNKNOWN_TABLE)

The "create table ... as ..." statement uses the default database after the "use" statement.

Expected behavior
The "create table ... as ..." statement should use the current used database.

Metadata

Metadata

Assignees

Labels

comp-ddlDDL command coordination and execution (ON CLUSTER, DDL queue).unexpected behaviourResult is unexpected, but not entirely wrong at the same time.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions