alter fix + test

This commit is contained in:
Nikita Vasilev 2019-01-16 20:59:47 +03:00
parent 2de2b6f32e
commit b4ce03ea7e
3 changed files with 70 additions and 2 deletions

View File

@ -321,7 +321,7 @@ void AlterCommand::apply(ColumnsDescription & columns_description, ASTPtr & orde
if (indexes_decl_ast) if (indexes_decl_ast)
new_indexes_decl_ast = indexes_decl_ast->clone(); new_indexes_decl_ast = indexes_decl_ast->clone();
else else
new_indexes_decl_ast = ASTExpressionList().ptr(); new_indexes_decl_ast = std::make_shared<ASTExpressionList>();
if (std::any_of( if (std::any_of(
new_indexes_decl_ast->children.cbegin(), new_indexes_decl_ast->children.cbegin(),
@ -363,7 +363,7 @@ void AlterCommand::apply(ColumnsDescription & columns_description, ASTPtr & orde
if (indexes_decl_ast) if (indexes_decl_ast)
new_indexes_decl_ast = indexes_decl_ast->clone(); new_indexes_decl_ast = indexes_decl_ast->clone();
else else
new_indexes_decl_ast = ASTExpressionList().ptr(); new_indexes_decl_ast = std::make_shared<ASTExpressionList>();
auto erase_it = std::find_if( auto erase_it = std::find_if(
new_indexes_decl_ast->children.begin(), new_indexes_decl_ast->children.begin(),

View File

@ -0,0 +1,68 @@
DROP TABLE IF EXISTS test.minmax_idx;
DROP TABLE IF EXISTS test.minmax_idx2;
CREATE TABLE test.minmax_idx
(
u64 UInt64,
i32 Int32
) ENGINE = MergeTree()
ORDER BY u64;
INSERT INTO test.minmax_idx VALUES (1, 2);
ALTER TABLE test.minmax_idx ADD INDEX idx1 BY u64 * i32 TYPE minmax GRANULARITY 10;
ALTER TABLE test.minmax_idx ADD INDEX idx2 BY u64 * i32 TYPE minmax GRANULARITY 10;
ALTER TABLE test.minmax_idx ADD INDEX idx3 BY u64 * i32 TYPE minmax GRANULARITY 10 AFTER idx1;
SHOW CREATE TABLE test.minmax_idx;
SELECT * FROM test.minmax_idx WHERE u64 * i32 = 3;
INSERT INTO test.minmax_idx VALUES (1, 2);
INSERT INTO test.minmax_idx VALUES (1, 2);
INSERT INTO test.minmax_idx VALUES (1, 2);
INSERT INTO test.minmax_idx VALUES (1, 2);
INSERT INTO test.minmax_idx VALUES (1, 2);
SELECT * FROM test.minmax_idx WHERE u64 * i32 = 3;
ALTER TABLE test.minmax_idx DROP INDEX idx1
SHOW CREATE TABLE test.minmax_idx;
SELECT * FROM test.minmax_idx WHERE u64 * i32 = 3;
ALTER TABLE test.minmax_idx DROP INDEX idx3;
ALTER TABLE test.minmax_idx DROP INDEX idx2;
SHOW CREATE TABLE test.minmax_idx;
ALTER TABLE test.minmax_idx ADD INDEX idx1 BY u64 * i32 TYPE minmax GRANULARITY 10;
SHOW CREATE TABLE test.minmax_idx;
SELECT * FROM test.minmax_idx WHERE u64 * i32 = 3;
CREATE TABLE test.minmax_idx2
(
u64 UInt64,
i32 Int32
) ENGINE = MergeTree()
idx2 BY u64 * i32 TYPE minmax GRANULARITY 10
INDEXES idx1 BY u64 * i32 TYPE minmax GRANULARITY 10,
ORDER BY u64;
INSERT INTO test.minmax_idx2 VALUES (1, 2);
INSERT INTO test.minmax_idx2 VALUES (1, 2);
SELECT * FROM test.minmax_idx2 WHERE u64 * i32 = 3;
ALTER TABLE test.minmax_idx2 DROP INDEX idx1, DROP INDEX idx2;
SHOW CREATE TABLE test.minmax_idx2;
SELECT * FROM test.minmax_idx2 WHERE u64 * i32 = 3;
DROP TABLE test.minmax_idx;
DROP TABLE test.minmax_idx2;