我正在学习如何在cassandra (想想twitter)中实现一个提要。我想使用宽行来存储用户创建的所有帖子。我正在考虑在同一行中添加用户信息或统计信息(帖子数、最后发布日期、用户名等)。
我的问题是:名称、年龄等“字段名”是否存储在列中?还是那些宽行只存储指定的列名和值?我在浪费磁盘空间吗?我是不是在某种程度上损害了表演?
谢谢!
-创建表格
CREATE TABLE user_feed (
owner_id int,
name text,
age int,
posted_at timestamp,
post_text text,
PRIMARY KEY (owner_id, posted_at)
);-插入用户
insert into user_feed (owner_id, name, age, posted_at) values (1, 'marc', 36, 0);-插入用户职位
insert into user_feed (owner_id, posted_at, post_text) values (1, dateof(now()), 'first post!');
insert into user_feed (owner_id, posted_at, post_text) values (1, dateof(now()), 'hello there');
insert into user_feed (owner_id, posted_at, post_text) values (1, dateof(now()), 'i am kind of happy');-得到饲料
select * from user_feed where owner_id=1 and posted_at>0;--结果
owner_id | posted_at | age | name | post_text
----------+--------------------------+------+------+--------------------
1 | 2014-07-04 12:01:23+0000 | null | null | first post!
1 | 2014-07-04 12:01:23+0000 | null | null | hello there
1 | 2014-07-04 12:01:23+0000 | null | null | i am kind of happy-获取用户信息-只有用户信息是POSTED_AT=0
select * from user_feed where owner_id=1 and posted_at=0;--结果
owner_id | posted_at | age | name | post_text
----------+--------------------------+------+------+--------------------
1 | 1970-01-01 00:00:00+0000 | 36 | marc | null发布于 2014-07-04 12:52:34
把它们弄成静态的怎么样?
静态列在所有分区键中都是相同的,而且由于分区键是所有者的id,因此可以避免浪费空间,并在任何查询中检索用户信息。
CREATE TABLE user_feed (
owner_id int,
name text static,
age int static,
posted_at timestamp,
post_text text,
PRIMARY KEY (owner_id, posted_at)
);干杯,卡洛
https://stackoverflow.com/questions/24574239
复制相似问题