ALTER TABLE ADD INDEX: Add default GRANULARITY argument for secondary indexes

- Related to #45451, which provides a default GRANULARITY when the
  skipping index is created in CREATE TABLE.
This commit is contained in:
Robert Schulze 2023-06-07 09:01:20 +00:00
parent 2989cd1d35
commit 4050b637f1
No known key found for this signature in database
GPG Key ID: 26703B55FB13728A
5 changed files with 15 additions and 6 deletions

View File

@ -10,7 +10,7 @@ sidebar_label: INDEX
The following operations are available: The following operations are available:
- `ALTER TABLE [db].table_name [ON CLUSTER cluster] ADD INDEX name expression TYPE type GRANULARITY value [FIRST|AFTER name]` - Adds index description to tables metadata. - `ALTER TABLE [db].table_name [ON CLUSTER cluster] ADD INDEX name expression TYPE type [GRANULARITY value] [FIRST|AFTER name]` - Adds index description to tables metadata.
- `ALTER TABLE [db].table_name [ON CLUSTER cluster] DROP INDEX name` - Removes index description from tables metadata and deletes index files from disk. Implemented as a [mutation](/docs/en/sql-reference/statements/alter/index.md#mutations). - `ALTER TABLE [db].table_name [ON CLUSTER cluster] DROP INDEX name` - Removes index description from tables metadata and deletes index files from disk. Implemented as a [mutation](/docs/en/sql-reference/statements/alter/index.md#mutations).

View File

@ -36,17 +36,20 @@ bool ParserCreateIndexDeclaration::parseImpl(Pos & pos, ASTPtr & node, Expected
if (!data_type_p.parse(pos, type, expected)) if (!data_type_p.parse(pos, type, expected))
return false; return false;
if (!s_granularity.ignore(pos, expected)) if (s_granularity.ignore(pos, expected))
return false; {
if (!granularity_p.parse(pos, granularity, expected))
return false;
}
if (!granularity_p.parse(pos, granularity, expected)) if (!granularity_p.parse(pos, granularity, expected))
return false; return false;
auto index = std::make_shared<ASTIndexDeclaration>(); auto index = std::make_shared<ASTIndexDeclaration>();
index->part_of_create_index_query = true; index->part_of_create_index_query = true;
index->granularity = granularity->as<ASTLiteral &>().value.safeGet<UInt64>();
index->set(index->expr, expr); index->set(index->expr, expr);
index->set(index->type, type); index->set(index->type, type);
index->granularity = granularity ? granularity->as<ASTLiteral &>().value.safeGet<UInt64>() : 1;
node = index; node = index;
return true; return true;

View File

@ -139,9 +139,9 @@ bool ParserIndexDeclaration::parseImpl(Pos & pos, ASTPtr & node, Expected & expe
auto index = std::make_shared<ASTIndexDeclaration>(); auto index = std::make_shared<ASTIndexDeclaration>();
index->name = name->as<ASTIdentifier &>().name(); index->name = name->as<ASTIdentifier &>().name();
index->granularity = granularity ? granularity->as<ASTLiteral &>().value.safeGet<UInt64>() : 1;
index->set(index->expr, expr); index->set(index->expr, expr);
index->set(index->type, type); index->set(index->type, type);
index->granularity = granularity ? granularity->as<ASTLiteral &>().value.safeGet<UInt64>() : 1;
node = index; node = index;
return true; return true;

View File

@ -1 +1,2 @@
CREATE TABLE default.users_02534\n(\n `id` Int16,\n `name` String,\n INDEX bf_idx name TYPE minmax GRANULARITY 1\n)\nENGINE = MergeTree\nORDER BY id\nSETTINGS index_granularity = 8192 CREATE TABLE default.users_02534\n(\n `id` Int16,\n `name` String,\n INDEX bf_idx name TYPE minmax GRANULARITY 1\n)\nENGINE = MergeTree\nORDER BY id\nSETTINGS index_granularity = 8192
CREATE TABLE default.users_02534\n(\n `id` Int16,\n `name` String,\n INDEX bf_idx name TYPE minmax GRANULARITY 1\n)\nENGINE = MergeTree\nORDER BY id\nSETTINGS index_granularity = 8192

View File

@ -2,3 +2,8 @@ DROP TABLE IF EXISTS users_02534;
CREATE TABLE users_02534 (id Int16, name String, INDEX bf_idx(name) TYPE minmax) ENGINE=MergeTree ORDER BY id; CREATE TABLE users_02534 (id Int16, name String, INDEX bf_idx(name) TYPE minmax) ENGINE=MergeTree ORDER BY id;
SHOW CREATE TABLE users_02534; SHOW CREATE TABLE users_02534;
DROP TABLE users_02534; DROP TABLE users_02534;
CREATE TABLE users_02534 (id Int16, name String) ENGINE=MergeTree ORDER BY id;
ALTER TABLE users_02534 ADD INDEX bf_idx(name) TYPE minmax;
SHOW CREATE TABLE users_02534;
DROP TABLE users_02534;