Cassandra 2-使用CQL 3列出现有索引

Cassandra 2-使用CQL 3列出现有索引,cassandra,cql,Cassandra,Cql,是否有CQL查询来列出特定键空间或列族的所有现有索引?您可以使用系统键空间检索主键和辅助索引: SELECT column_name, index_name, index_options, index_type, component_index FROM system.schema_columns WHERE keyspace_name='samplekp'AND columnfamily_name='sampletable'; 以下表声明为例: CREATE TABLE sampleta

是否有CQL查询来列出特定键空间或列族的所有现有索引?

您可以使用系统键空间检索主键和辅助索引:

SELECT column_name, index_name, index_options, index_type, component_index 
FROM system.schema_columns 
WHERE keyspace_name='samplekp'AND columnfamily_name='sampletable';
以下表声明为例:

CREATE TABLE sampletable (
key text,
date timestamp,
value1 text,
value2 text,
PRIMARY KEY(key, date));

CREATE INDEX ix_sample_value2 ON sampletable (value2);
上述查询将得到以下结果:

 column_name | index_name       | index_options | index_type | component_index
-------------+------------------+---------------+------------+-----------------
        date |             null |          null |       null |               0
         key |             null |          null |       null |            null
      value1 |             null |          null |       null |               1
      value2 | ix_sample_value2 |            {} | COMPOSITES |               1

最简单的方法是使用
DESC
命令


DESC TABLE“TABLE_Name”
获取您想要的内容

假设您有一个名为
moviesongs的表
,启动一个语句作为
描述moviesongs
cqlsh:system> show version
[cqlsh 5.0.1 | Cassandra 2.1.2-SNAPSHOT | CQL spec 3.2.0 | Native protocol v3]


cqlsh:system> desc table "IndexInfo"

CREATE TABLE system."IndexInfo" (
table_name text,
index_name text,
"" blob,
PRIMARY KEY (table_name, index_name)
) WITH COMPACT STORAGE
AND CLUSTERING ORDER BY (index_name ASC)
AND bloom_filter_fp_chance = 0.01
AND caching = '{"keys":"ALL", "rows_per_partition":"NONE"}'
AND comment = 'indexes that have been completed'
AND compaction = {'min_threshold': '4', 'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32'}
AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND dclocal_read_repair_chance = 0.0
AND default_time_to_live = 0
AND gc_grace_seconds = 0
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 3600000
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99.0PERCENTILE';

cqlsh:system> select * from "IndexInfo";

 table_name | index_name
------------+---------------------------------
    musicdb | performer.performer_country_key
    musicdb |   performer.performer_style_key
    musicdb |       user.user_preferences_key

(3 rows)
您将获得以下输出:

cqlsh:practice> describe moviesongs ;

CREATE TABLE practice.moviesongs (
    moviename text,
    year int,
    songname text,
    songnum int,
    PRIMARY KEY (moviename, year)
) WITH CLUSTERING ORDER BY (year DESC)
    AND 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 index1 ON practice.moviesongs (year);
看最后一行,它描述了
moviesongs
表上的索引