【问题标题】:Extra column created by CQL inserts (comparing to cli)CQL 插入创建的额外列(与 cli 相比)
【发布时间】:2013-05-22 18:12:25
【问题描述】:

当我使用 cql 与 cli 相比时,我看到在我的列族中创建了额外的列。

使用 CQL 创建表并插入行:

cqlsh:cassandraSample> CREATE TABLE bedbugs(
               ...     id varchar,
               ...     name varchar,
               ...     description varchar,
               ...     primary key(id, name)
               ... )  ;

cqlsh:cassandraSample> insert into bedbugs (id, name, description) 
values ('Cimex','Cimex lectularius','http://en.wikipedia.org/wiki/Bed_bug');

现在使用 cli 插入列:

[default@cassandraSample] set bedbugs['BatBedBug']['C. pipistrelli:description']='google.com';
Value inserted.
Elapsed time: 1.82 msec(s).
[default@cassandraSample] list bedbugs
...     ;
Using default limit of 100
Using default column limit of 100
-------------------
RowKey: Cimex
=> (column=Cimex lectularius:, value=, timestamp=1369682957658000)
=> (column=Cimex lectularius:description, value=http://en.wikipedia.org/wiki/Bed_bug, timestamp=1369682957658000)
-------------------
RowKey: BatBedBug
=> (column=C. pipistrelli:description, value=google.com, timestamp=1369688651442000)

2 Rows Returned.


cqlsh:cassandraSample> select * from bedbugs;

 id        | name              | description
-----------+-------------------+--------------------------------------
     Cimex | Cimex lectularius | http://en.wikipedia.org/wiki/Bed_bug
 BatBedBug |    C. pipistrelli |                           google.com

因此,cql 为每一行创建一个额外的列,其中包含空的非主键列。不是很浪费空间吗?

【问题讨论】:

    标签: cassandra cql cassandra-cli


    【解决方案1】:

    当您使用 CQLSh 创建列族并指定主键 (Id, name) 时,您让 cassandra 为存储的数据创建两个索引,一个用于按 ID 排序的数据,另一个用于按名称排序的数据。但是当您通过 cassandra-cli 执行此操作时,您的列族没有索引列。 cassandra-cli 不支持二级索引。我希望我对你有意义我缺乏语言来解释我的理解。

    【讨论】:

      【解决方案2】:

      为了与 cassandra-cli 兼容并防止创建此额外列,请将您的 create table 语句更改为包含“WITH COMPACT STORAGE”。

      described here

      所以

      CREATE TABLE bedbugs(
        id varchar,
        name varchar,
        description varchar,
        primary key(id, name)
      );
      

      变成

      CREATE TABLE bedbugs(
        id varchar,
        name varchar,
        description varchar,
        primary key(id, name)
      ) WITH COMPACT STORAGE;
      

      COMPACT STORAGE 也是您在 cql 中支持 wide rows 的方式。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-03-26
        • 1970-01-01
        • 2013-07-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-07
        相关资源
        最近更新 更多