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

Mac*_*las 11 cql cassandra

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

jor*_*ebg 18

您可以使用系统密钥空间检索主键和二级索引:

SELECT column_name, index_name, index_options, index_type, component_index 
FROM system.schema_columns 
WHERE keyspace_name='samplekp'AND columnfamily_name='sampletable';
Run Code Online (Sandbox Code Playgroud)

以下表声明为例:

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

CREATE INDEX ix_sample_value2 ON sampletable (value2);
Run Code Online (Sandbox Code Playgroud)

上面提到的查询会得到以下结果:

 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
Run Code Online (Sandbox Code Playgroud)


小智 9

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

DESC TABLE "Table_Name" 得到你想要的