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

时间:2014-01-13 13:30:05

标签: cassandra cql

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

4 个答案:

答案 0 :(得分:16)

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

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

答案 1 :(得分:9)

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

DESC TABLE "Table_Name"得到你想要的东西

答案 2 :(得分:2)

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)

答案 3 :(得分:0)

假设您有一个名为moviesongs的表,则将语句激发为DESCRIBE moviesongs; 您将获得以下输出:

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表上的索引