mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
Merge pull request #5524 from NanoBjorn/fix-drop-index-if-exists
Fixed DROP INDEX IF EXISTS and added simple test
This commit is contained in:
commit
b7248803d5
@ -293,8 +293,12 @@ void AlterCommand::apply(ColumnsDescription & columns_description, IndicesDescri
|
||||
});
|
||||
|
||||
if (erase_it == indices_description.indices.end())
|
||||
{
|
||||
if (if_exists)
|
||||
return;
|
||||
throw Exception("Wrong index name. Cannot find index `" + index_name + "` to drop.",
|
||||
ErrorCodes::LOGICAL_ERROR);
|
||||
ErrorCodes::LOGICAL_ERROR);
|
||||
}
|
||||
|
||||
indices_description.indices.erase(erase_it);
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
ok
|
26
dbms/tests/queries/0_stateless/00953_indices_alter_exceptions.sh
Executable file
26
dbms/tests/queries/0_stateless/00953_indices_alter_exceptions.sh
Executable file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
. $CURDIR/../shell_config.sh
|
||||
|
||||
EXCEPTION_SUCCESS_TEXT=ok
|
||||
|
||||
$CLICKHOUSE_CLIENT --query="DROP TABLE IF EXISTS test_drop_indices;"
|
||||
|
||||
$CLICKHOUSE_CLIENT --query="CREATE TABLE test_drop_indices
|
||||
(
|
||||
a UInt32,
|
||||
b UInt32
|
||||
)
|
||||
ENGINE = MergeTree ORDER BY (a);"
|
||||
|
||||
# Must throw an exception
|
||||
EXCEPTION_TEXT="Cannot find index \`test_index\` to drop.."
|
||||
$CLICKHOUSE_CLIENT --query="ALTER TABLE test_drop_indices DROP INDEX test_index;" 2>&1 \
|
||||
| grep -q "$EXCEPTION_TEXT" && echo "$EXCEPTION_SUCCESS_TEXT" || echo "Did not thrown an exception"
|
||||
|
||||
# Must not throw an exception
|
||||
$CLICKHOUSE_CLIENT --query="ALTER TABLE test_drop_indices DROP INDEX IF EXISTS test_index"
|
||||
|
||||
$CLICKHOUSE_CLIENT --query="DROP TABLE test_drop_indices;"
|
||||
|
Loading…
Reference in New Issue
Block a user