在关系数据库中,我们通过使用联结表来建立多对多关系,但在Cassandra上,以形式存储多对多关系的最佳实践是什么,我们可以限制行的关系结果,假设我们有一个"鸣叫"桌子,我想要商店"喜欢"用户的事件,每个像行一样是用户定义类型,如下所述:
CREATE TYPE social.likes (
liker_user_id int,
action_time timestamp;
);
和推文表描述如下:
CREATE TABLE social.tweets (
owner_id bigint,
id uuid,
"_short_content" text,
comments list<frozen<likes>>,
content text,
created_time timestamp,
image text,
images text,
thumbnail text,
title text,
PRIMARY KEY (owner_id, id)
) WITH CLUSTERING ORDER BY (id ASC)
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';
现在假设在社交项目中我们有一千万个喜欢的推文,我怎么能只通过使用CQL喜欢这个推文的前十个用户得到这个推文?