“Solicitação incorreta: a parte PRIMARY KEY to_id não pode ser restrita” ao tentar selecionar usando a condição where
Aqui está minha tabela cassandra para o tipo de aplicativo de bate-papo:
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)
);
Esta consulta funciona:
select * from tax_keyspace_dev.chat_messages where participants='[email protected][email protected]' order by when;
mas as consultas a seguir não funcionam:
select * from tax_keyspace_dev.chat_messages where to_id='[email protected]' order by when;
O erro é "Solicitação incorreta: a parte PRIMARY KEY to_id não pode ser restrita (parte anterior quando não é restrita ou por uma relação não-EQ)"
update tax_keyspace_dev.chat_messages set read=true where participants = '[email protected][email protected]' and when = '2014-04-10 17:44:22+0530';
O erro é "Solicitação incorreta: falta de parte obrigatória da PRIMARY KEY to_id"
Se eu remover "to_id" da chave composta e criar um índice separado como este:
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);
outras consultas funcionam, mas esta falha:
select * from tax_keyspace_dev.chat_messages where to_id='[email protected]' order by when;
com erro "Solicitação incorreta: ORDER BY com índices secundários não é suportado."
Como faço para projetar minha tabela para que todos esses casos de uso funcionem?
select * from tax_keyspace_dev.chat_messages where participants='[email protected][email protected]' order by when;
update tax_keyspace_dev.chat_messages set read=true where participants = '[email protected][email protected]' and when = '2014-04-10 17:44:22+0530';
select * from tax_keyspace_dev.chat_messages where to_id='[email protected]' order by when;