Merge branch 'master' of github.com:ClickHouse/ClickHouse into zvonand-implicit-tz

This commit is contained in:
zvonand 2023-05-10 14:49:17 +02:00
commit 7762dde325
6 changed files with 82 additions and 7 deletions

View File

@ -103,7 +103,11 @@ ALTER TABLE table2 [ON CLUSTER cluster] ATTACH PARTITION partition_expr FROM tab
```
This query copies the data partition from `table1` to `table2`.
Note that data will be deleted neither from `table1` nor from `table2`.
Note that:
- Data will be deleted neither from `table1` nor from `table2`.
- `table1` may be a temporary table.
For the query to run successfully, the following conditions must be met:
@ -117,7 +121,12 @@ For the query to run successfully, the following conditions must be met:
ALTER TABLE table2 [ON CLUSTER cluster] REPLACE PARTITION partition_expr FROM table1
```
This query copies the data partition from the `table1` to `table2` and replaces existing partition in the `table2`. Note that data wont be deleted from `table1`.
This query copies the data partition from the `table1` to `table2` and replaces existing partition in the `table2`.
Note that:
- Data wont be deleted from `table1`.
- `table1` may be a temporary table.
For the query to run successfully, the following conditions must be met:

View File

@ -1,7 +1,7 @@
---
slug: /en/sql-reference/table-functions/dictionary
sidebar_position: 54
sidebar_label: dictionary function
sidebar_label: dictionary
title: dictionary
---

View File

@ -102,7 +102,11 @@ ALTER TABLE table2 [ON CLUSTER cluster] ATTACH PARTITION partition_expr FROM tab
```
Копирует партицию из таблицы `table1` в таблицу `table2`.
Обратите внимание, что данные не удаляются ни из `table1`, ни из `table2`.
Обратите внимание, что:
- Данные не удаляются ни из `table1`, ни из `table2`.
- `table1` может быть временной таблицей.
Следует иметь в виду:
@ -118,7 +122,12 @@ ALTER TABLE table2 [ON CLUSTER cluster] ATTACH PARTITION partition_expr FROM tab
ALTER TABLE table2 [ON CLUSTER cluster] REPLACE PARTITION partition_expr FROM table1
```
Копирует партицию из таблицы `table1` в таблицу `table2` с заменой существующих данных в `table2`. Данные из `table1` не удаляются.
Копирует партицию из таблицы `table1` в таблицу `table2` с заменой существующих данных в `table2`.
Обратите внимание, что:
- Данные из `table1` не удаляются.
- `table1` может быть временной таблицей.
Следует иметь в виду:

View File

@ -4985,8 +4985,8 @@ Pipe MergeTreeData::alterPartition(
if (command.replace)
checkPartitionCanBeDropped(command.partition, query_context);
String from_database = query_context->resolveDatabase(command.from_database);
auto from_storage = DatabaseCatalog::instance().getTable({from_database, command.from_table}, query_context);
auto resolved = query_context->resolveStorageID({command.from_database, command.from_table});
auto from_storage = DatabaseCatalog::instance().getTable(resolved, query_context);
auto * from_storage_merge_tree = dynamic_cast<MergeTreeData *>(from_storage.get());
if (!from_storage_merge_tree)

View File

@ -0,0 +1,9 @@
Initial
6 12
6 12
REPLACE simple
6 10
6 10
ATTACH FROM
6 10
6 10

View File

@ -0,0 +1,48 @@
-- Tags: no-replicated-database
DROP TEMPORARY TABLE IF EXISTS src;
DROP TABLE IF EXISTS dst;
DROP TABLE IF EXISTS rdst;
CREATE TEMPORARY TABLE src (p UInt64, k String, d UInt64) ENGINE = MergeTree PARTITION BY p ORDER BY k;
CREATE TABLE dst (p UInt64, k String, d UInt64) ENGINE = MergeTree PARTITION BY p ORDER BY k;
CREATE TABLE rdst (p UInt64, k String, d UInt64) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{database}/test_alter_attach_00626_rdst', 'r1') PARTITION BY p ORDER BY k;
SELECT 'Initial';
INSERT INTO src VALUES (0, '0', 1);
INSERT INTO src VALUES (1, '0', 1);
INSERT INTO src VALUES (1, '1', 1);
INSERT INTO src VALUES (2, '0', 1);
INSERT INTO src VALUES (3, '0', 1);
INSERT INTO src VALUES (3, '1', 1);
INSERT INTO dst VALUES (0, '1', 2);
INSERT INTO dst VALUES (1, '1', 2), (1, '2', 2);
INSERT INTO dst VALUES (2, '1', 2);
INSERT INTO dst VALUES (3, '1', 2), (3, '2', 2);
INSERT INTO rdst VALUES (0, '1', 2);
INSERT INTO rdst VALUES (1, '1', 2), (1, '2', 2);
INSERT INTO rdst VALUES (2, '1', 2);
INSERT INTO rdst VALUES (3, '1', 2), (3, '2', 2);
SELECT count(), sum(d) FROM dst;
SELECT count(), sum(d) FROM rdst;
SELECT 'REPLACE simple';
ALTER TABLE dst REPLACE PARTITION 1 FROM src;
SELECT count(), sum(d) FROM dst;
ALTER TABLE rdst REPLACE PARTITION 3 FROM src;
SELECT count(), sum(d) FROM rdst;
SELECT 'ATTACH FROM';
ALTER TABLE dst DROP PARTITION 1;
ALTER TABLE dst ATTACH PARTITION 1 FROM src;
SELECT count(), sum(d) FROM dst;
ALTER TABLE rdst DROP PARTITION 3;
ALTER TABLE rdst ATTACH PARTITION 1 FROM src;
SELECT count(), sum(d) FROM rdst;
DROP TEMPORARY TABLE IF EXISTS src;
DROP TABLE IF EXISTS dst;
DROP TABLE IF EXISTS rdst;