DROP INDEX
命令用於刪除指定的索引。 如果索引建立時未指定索引名稱,則索引名稱為TableName_ColumnName_idx
。
語法
DROP INDEX <identifier>
或者 -
Drop index IF EXISTS KeyspaceName.IndexName
刪除索引的規則
IF EXISTS
,否則不返回任何操作。keyspace
名稱,否則將當前鍵空間中的索引刪除。範例:
下面舉個例子來演示如何刪除某列上的索引。 在這裡,我們將建立的索引放在表「student
」中的「student_name
」列中。鍵空間的名稱是「yiibai_ks
」。
Drop index IF EXISTS yiibai_ks.student_name_index;
如下語句 -
## 首先建立一個索引: student_name_index
cqlsh:yiibai_ks> CREATE INDEX student_name_index ON student (student_name);
cqlsh:yiibai_ks> describe student;
CREATE TABLE yiibai_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 yiibai_ks.student (student_name);
## 刪除索引 = student_name_index
cqlsh:yiibai_ks> Drop index IF EXISTS student_name_index;
cqlsh:yiibai_ks> describe student;
CREATE TABLE yiibai_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:yiibai_ks>
從「student_name
」列中刪除索引。
注意:通過再次使用DROP索引命令,可以驗證索引是否被刪除。 它將顯示一條訊息,索引已經被刪除。
cqlsh:yiibai_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 'yiibai_ks'"
cqlsh:yiibai_ks>