Allow RENAME of index columns.

This commit is contained in:
Amos Bird 2023-11-19 12:00:21 +08:00
parent 6581aaf9e8
commit ee1cec4d38
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
4 changed files with 32 additions and 4 deletions

View File

@ -3047,8 +3047,7 @@ void MergeTreeData::checkAlterIsPossible(const AlterCommands & commands, Context
backQuoteIfNeed(command.column_name));
}
/// Don't check columns in indices here. If required columns of indices get renamed, it
/// will be checked later in AlterCommands::apply.
/// Don't check columns in indices here. RENAME works fine with index columns.
if (auto it = columns_in_projections.find(command.column_name); it != columns_in_projections.end())
{

View File

@ -52,6 +52,4 @@ ALTER TABLE table_for_rename_with_primary_key RENAME COLUMN key2 TO renamed_key2
ALTER TABLE table_for_rename_with_primary_key RENAME COLUMN key3 TO renamed_key3; --{serverError 524}
ALTER TABLE table_for_rename_with_primary_key RENAME COLUMN value1 TO renamed_value1; --{serverError 524}
DROP TABLE IF EXISTS table_for_rename_with_primary_key;

View File

@ -0,0 +1,31 @@
DROP TABLE IF EXISTS t;
CREATE TABLE t
(
key1 UInt64,
value1 String,
value2 String,
INDEX idx (value1) TYPE set(10) GRANULARITY 1
)
ENGINE MergeTree ORDER BY key1 SETTINGS index_granularity = 1;
INSERT INTO t SELECT toDate('2019-10-01') + number % 3, toString(number), toString(number) from numbers(9);
SYSTEM STOP MERGES t;
SET alter_sync = 0;
ALTER TABLE t RENAME COLUMN value1 TO value11;
-- Index works without mutation applied.
SELECT * FROM t WHERE value11 = '000' SETTINGS max_rows_to_read = 0;
SYSTEM START MERGES t;
-- Another ALTER to wait for.
ALTER TABLE t RENAME COLUMN value11 TO value12 SETTINGS mutations_sync = 2;
-- Index works with mutation applied.
SELECT * FROM t WHERE value12 = '000' SETTINGS max_rows_to_read = 0;
DROP TABLE t;