DROP INDEX
命令用于删除指定的索引。 如果索引创建时未指定索引名称,则索引名称为TableName_ColumnName_idx
。
语法
DROP INDEX <identifier>
或者 -
Drop index IF EXISTS KeyspaceName.IndexName
删除索引的规则
IF EXISTS
,否则不返回任何操作。keyspace
名称,否则将当前键空间中的索引删除。示例:
下面举个例子来演示如何删除某列上的索引。 在这里,我们将创建的索引放在表“student
”中的“student_name
”列中。键空间的名称是“zyiz_ks
”。
Drop index IF EXISTS zyiz_ks.student_name_index;
如下语句 -
## 首先创建一个索引: student_name_index cqlsh:zyiz_ks> CREATE INDEX student_name_index ON student (student_name); cqlsh:zyiz_ks> describe student; CREATE TABLE zyiz_ks.student ( student_id int PRIMARY KEY, student_fees varint, student_name text ) WITH bloom_filter_fp_chance = 0.01 AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'} AND comment = '' AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'} AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'} AND crc_check_chance = 1.0 AND dclocal_read_repair_chance = 0.1 AND default_time_to_live = 0 AND gc_grace_seconds = 864000 AND max_index_interval = 2048 AND memtable_flush_period_in_ms = 0 AND min_index_interval = 128 AND read_repair_chance = 0.0 AND speculative_retry = '99PERCENTILE'; CREATE INDEX student_name_index ON zyiz_ks.student (student_name); ## 删除索引 = student_name_index cqlsh:zyiz_ks> Drop index IF EXISTS student_name_index; cqlsh:zyiz_ks> describe student; CREATE TABLE zyiz_ks.student ( student_id int PRIMARY KEY, student_fees varint, student_name text ) WITH bloom_filter_fp_chance = 0.01 AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'} AND comment = '' AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'} AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'} AND crc_check_chance = 1.0 AND dclocal_read_repair_chance = 0.1 AND default_time_to_live = 0 AND gc_grace_seconds = 864000 AND max_index_interval = 2048 AND memtable_flush_period_in_ms = 0 AND min_index_interval = 128 AND read_repair_chance = 0.0 AND speculative_retry = '99PERCENTILE'; cqlsh:zyiz_ks>
从“student_name
”列中删除索引。
注意:通过再次使用DROP索引命令,可以验证索引是否被删除。 它将显示一条消息,索引已经被删除。
cqlsh:zyiz_ks> Drop index student_name_index; InvalidRequest: Error from server: code=2200 [Invalid query] message="Index 'student_name_index' could not be found in any of the tables of keyspace 'zyiz_ks'" cqlsh:zyiz_ks>