【问题标题】:Cassandra 2 - list existing indexes with CQL 3Cassandra 2 - 使用 CQL 3 列出现有索引
【发布时间】:2014-02-01 06:31:20
【问题描述】:

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

【问题讨论】:

    标签: cassandra cql


    【解决方案1】:

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

    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
    

    【讨论】:

      【解决方案2】:

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

      DESC TABLE "Table_Name" 得到你想要的

      【讨论】:

        【解决方案3】:
        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)
        

        【讨论】:

          【解决方案4】:

          假设您有一个名为 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表上的索引

          【讨论】:

            猜你喜欢
            • 2012-06-23
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2015-05-05
            • 2014-01-03
            • 2014-08-20
            • 1970-01-01
            相关资源
            最近更新 更多