mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-03 13:02:00 +00:00
More compatible way
This commit is contained in:
parent
59ca0d071c
commit
b28894c43b
@ -608,29 +608,23 @@ static StoragePtr create(const StorageFactory::Arguments & args)
|
||||
/// single default partition with name "all".
|
||||
metadata.partition_key = KeyDescription::getKeyFromAST(partition_by_key, metadata.columns, args.context);
|
||||
|
||||
/// PRIMARY KEY without ORDER BY is allowed and considered as ORDER BY.
|
||||
if (!args.storage_def->order_by && args.storage_def->primary_key)
|
||||
args.storage_def->order_by = args.storage_def->primary_key;
|
||||
|
||||
/// Get sorting key from engine arguments. PRIMARY KEY without ORDER BY is allowed and considered as ORDER BY.
|
||||
///
|
||||
/// NOTE: store merging_param_key_arg as additional key column. We do it
|
||||
/// before storage creation. After that storage will just copy this
|
||||
/// column if sorting key will be changed.
|
||||
if (args.storage_def->order_by)
|
||||
{
|
||||
metadata.sorting_key = KeyDescription::getSortingKeyFromAST(
|
||||
args.storage_def->order_by->ptr(), metadata.columns, args.context, merging_param_key_arg);
|
||||
}
|
||||
else if (args.storage_def->primary_key)
|
||||
{
|
||||
metadata.sorting_key = KeyDescription::getSortingKeyFromAST(
|
||||
args.storage_def->primary_key->ptr(), metadata.columns, args.context, merging_param_key_arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!args.storage_def->order_by)
|
||||
throw Exception(
|
||||
"You must provide an ORDER BY or PRIMARY KEY expression in the table definition. "
|
||||
"If you don't want this table to be sorted, use ORDER BY/PRIMARY KEY tuple()",
|
||||
ErrorCodes::BAD_ARGUMENTS);
|
||||
}
|
||||
|
||||
/// Get sorting key from engine arguments.
|
||||
///
|
||||
/// NOTE: store merging_param_key_arg as additional key column. We do it
|
||||
/// before storage creation. After that storage will just copy this
|
||||
/// column if sorting key will be changed.
|
||||
metadata.sorting_key = KeyDescription::getSortingKeyFromAST(
|
||||
args.storage_def->order_by->ptr(), metadata.columns, args.context, merging_param_key_arg);
|
||||
|
||||
/// If primary key explicitly defined, than get it from AST
|
||||
if (args.storage_def->primary_key)
|
||||
|
@ -1,9 +1,9 @@
|
||||
CREATE TABLE default.merge_tree_pk\n(\n `key` UInt64,\n `value` String\n)\nENGINE = ReplacingMergeTree()\nPRIMARY KEY key\nSETTINGS index_granularity = 8192
|
||||
CREATE TABLE default.merge_tree_pk\n(\n `key` UInt64,\n `value` String\n)\nENGINE = ReplacingMergeTree()\nPRIMARY KEY key\nORDER BY key\nSETTINGS index_granularity = 8192
|
||||
1 a
|
||||
2 b
|
||||
1 c
|
||||
2 b
|
||||
CREATE TABLE default.merge_tree_pk_sql\n(\n `key` UInt64,\n `value` String\n)\nENGINE = ReplacingMergeTree()\nPRIMARY KEY key\nSETTINGS index_granularity = 8192
|
||||
CREATE TABLE default.merge_tree_pk_sql\n(\n `key` UInt64,\n `value` String\n)\nENGINE = ReplacingMergeTree()\nPRIMARY KEY key\nORDER BY key\nSETTINGS index_granularity = 8192
|
||||
1 a
|
||||
2 b
|
||||
1 c
|
||||
@ -12,7 +12,7 @@ CREATE TABLE default.merge_tree_pk_sql\n(\n `key` UInt64,\n `value` String
|
||||
2 e 555
|
||||
2 b 0
|
||||
CREATE TABLE default.merge_tree_pk_sql\n(\n `key` UInt64,\n `value` String,\n `key2` UInt64\n)\nENGINE = ReplacingMergeTree()\nPRIMARY KEY key\nORDER BY (key, key2)\nSETTINGS index_granularity = 8192
|
||||
CREATE TABLE default.replicated_merge_tree_pk_sql\n(\n `key` UInt64,\n `value` String\n)\nENGINE = ReplicatedReplacingMergeTree(\'/clickhouse/test/01532_primary_key_without\', \'r1\')\nPRIMARY KEY key\nSETTINGS index_granularity = 8192
|
||||
CREATE TABLE default.replicated_merge_tree_pk_sql\n(\n `key` UInt64,\n `value` String\n)\nENGINE = ReplicatedReplacingMergeTree(\'/clickhouse/test/01532_primary_key_without\', \'r1\')\nPRIMARY KEY key\nORDER BY key\nSETTINGS index_granularity = 8192
|
||||
1 a
|
||||
2 b
|
||||
1 c
|
||||
|
Loading…
Reference in New Issue
Block a user