Cassandra 2 - list existing indexes with CQL 3

后端 未结 4 1714
北恋
北恋 2020-12-30 08:10

Is there a CQL query to list all existing indexes for particular key space, or column family?

4条回答
  •  天涯浪人
    2020-12-30 08:27

    You can retrieve primary keys and secondary indexes using the system keyspace:

    SELECT column_name, index_name, index_options, index_type, component_index 
    FROM system.schema_columns 
    WHERE keyspace_name='samplekp'AND columnfamily_name='sampletable';
    

    Taking, for example, the following table declaration:

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

    The query mentioned above would get something this results:

     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
    

提交回复
热议问题