これは、チャットの種類のアプリケーション用の私の cassandra テーブルです。
CREATE TABLE tax_keyspace_dev.chat_messages (
message text,
when timestamp,
from_id text,
to_id text,
read boolean,
participants text,
PRIMARY KEY(participants, when, to_id)
);
このクエリは次のように機能します。
select * from tax_keyspace_dev.chat_messages where participants='caone@one.com_shashank_shrivastava@acme.com' order by when;
ただし、次のクエリは機能しません。
select * from tax_keyspace_dev.chat_messages where to_id='caone@one.com' order by when;
エラーは「Bad Request: PRIMARY KEY part to_id cannot be restricted (先行部分が制限されていないか、非 EQ 関係による場合)」です。
update tax_keyspace_dev.chat_messages set read=true where participants = 'caone@one.com_shashank_shrivastava@acme.com' and when = '2014-04-10 17:44:22+0530';
エラーは「Bad Request: Missing Required PRIMARY KEY part to_id」です
複合キーから「to_id」を削除し、次のように別のインデックスを作成すると:
CREATE TABLE tax_keyspace_dev.chat_messages (
message text,
when timestamp,
from_id text,
to_id text,
read boolean,
participants text,
PRIMARY KEY(participants, when)
);
CREATE INDEX idx_chat_messages_to ON tax_keyspace_dev.chat_messages (to_id);
その後、他のクエリは機能しますが、これは失敗します:
select * from tax_keyspace_dev.chat_messages where to_id='caone@one.com' order by when;
エラー「不正な要求: 2 番目のインデックスを使用した ORDER BY はサポートされていません。」
これらすべてのユースケースが機能するようにテーブルを設計するにはどうすればよいですか?
select * from tax_keyspace_dev.chat_messages where participants='caone@one.com_shashank_shrivastava@acme.com' order by when;
update tax_keyspace_dev.chat_messages set read=true where participants = 'caone@one.com_shashank_shrivastava@acme.com' and when = '2014-04-10 17:44:22+0530';
select * from tax_keyspace_dev.chat_messages where to_id='caone@one.com' order by when;