mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 23:52:03 +00:00
Merge pull request #45451 from evillique/default_granularity
Add default GRANULARITY argument for secondary indexes
This commit is contained in:
commit
2066581d8f
@ -40,8 +40,8 @@ CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
|
|||||||
name1 [type1] [DEFAULT|MATERIALIZED|ALIAS expr1] [TTL expr1],
|
name1 [type1] [DEFAULT|MATERIALIZED|ALIAS expr1] [TTL expr1],
|
||||||
name2 [type2] [DEFAULT|MATERIALIZED|ALIAS expr2] [TTL expr2],
|
name2 [type2] [DEFAULT|MATERIALIZED|ALIAS expr2] [TTL expr2],
|
||||||
...
|
...
|
||||||
INDEX index_name1 expr1 TYPE type1(...) GRANULARITY value1,
|
INDEX index_name1 expr1 TYPE type1(...) [GRANULARITY value1],
|
||||||
INDEX index_name2 expr2 TYPE type2(...) GRANULARITY value2,
|
INDEX index_name2 expr2 TYPE type2(...) [GRANULARITY value2],
|
||||||
...
|
...
|
||||||
PROJECTION projection_name_1 (SELECT <COLUMN LIST EXPR> [GROUP BY] [ORDER BY]),
|
PROJECTION projection_name_1 (SELECT <COLUMN LIST EXPR> [GROUP BY] [ORDER BY]),
|
||||||
PROJECTION projection_name_2 (SELECT <COLUMN LIST EXPR> [GROUP BY] [ORDER BY])
|
PROJECTION projection_name_2 (SELECT <COLUMN LIST EXPR> [GROUP BY] [ORDER BY])
|
||||||
@ -359,13 +359,15 @@ ClickHouse uses this logic not only for days of the month sequences, but for any
|
|||||||
The index declaration is in the columns section of the `CREATE` query.
|
The index declaration is in the columns section of the `CREATE` query.
|
||||||
|
|
||||||
``` sql
|
``` sql
|
||||||
INDEX index_name expr TYPE type(...) GRANULARITY granularity_value
|
INDEX index_name expr TYPE type(...) [GRANULARITY granularity_value]
|
||||||
```
|
```
|
||||||
|
|
||||||
For tables from the `*MergeTree` family, data skipping indices can be specified.
|
For tables from the `*MergeTree` family, data skipping indices can be specified.
|
||||||
|
|
||||||
These indices aggregate some information about the specified expression on blocks, which consist of `granularity_value` granules (the size of the granule is specified using the `index_granularity` setting in the table engine). Then these aggregates are used in `SELECT` queries for reducing the amount of data to read from the disk by skipping big blocks of data where the `where` query cannot be satisfied.
|
These indices aggregate some information about the specified expression on blocks, which consist of `granularity_value` granules (the size of the granule is specified using the `index_granularity` setting in the table engine). Then these aggregates are used in `SELECT` queries for reducing the amount of data to read from the disk by skipping big blocks of data where the `where` query cannot be satisfied.
|
||||||
|
|
||||||
|
The `GRANULARITY` clause can be omitted, the default value of `granularity_value` is 1.
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
|
|
||||||
``` sql
|
``` sql
|
||||||
|
@ -131,15 +131,15 @@ bool ParserIndexDeclaration::parseImpl(Pos & pos, ASTPtr & node, Expected & expe
|
|||||||
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))
|
||||||
if (!granularity_p.parse(pos, granularity, expected))
|
return false;
|
||||||
return false;
|
}
|
||||||
|
|
||||||
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->as<ASTLiteral &>().value.safeGet<UInt64>();
|
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);
|
||||||
node = index;
|
node = index;
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
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
|
4
tests/queries/0_stateless/02534_default_granularity.sql
Normal file
4
tests/queries/0_stateless/02534_default_granularity.sql
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
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;
|
||||||
|
SHOW CREATE TABLE users_02534;
|
||||||
|
DROP TABLE users_02534;
|
Loading…
Reference in New Issue
Block a user