1 回答
TA贡献1936条经验 获得超6个赞
最好的方法?为您要服务的每个查询创建一个表。使用您要查询的列和(id以确保唯一性)构建 PRIMARY KEY 定义:
CREATE TABLE IF NOT EXISTS messages_by_email (
id UUID,
email TEXT,
title TEXT,
content TEXT,
number BIGINT,
date_created TIMESTAMP,
PRIMARY KEY (email,id));
CREATE TABLE IF NOT EXISTS messages_by_number (
....
PRIMARY KEY (number,id));
当您向这些表写入一行时,请使用BATCH以确保原子性。
BEGIN BATCH
INSERT INTO messages (id,email,number,title,content,date_created)
VALUES (uuid(),'aaron@dot.com',1,'Hi','Cassandra rocks!',toTimestamp(now()));
INSERT INTO messages_by_email (id,email,number,title,content,date_created)
VALUES (uuid(),'aaron@dot.com',1,'Hi','Cassandra rocks!',toTimestamp(now()));
INSERT INTO messages_by_number (id,email,number,title,content,date_created)
VALUES (uuid(),'aaron@dot.com',1,'Hi','Cassandra rocks!',toTimestamp(now()));
APPLY BATCH;
- 1 回答
- 0 关注
- 80 浏览
添加回答
举报