Cassandra cqlsh not working with where clause on non-partition key

扶醉桌前 提交于 2019-12-12 14:09:10

问题


My table describe is :

CREATE TABLE user (
    id text,
    CustID int static,
    UpdateDate date,
    DateOfBirth date static,
    Gender text static,
    Address text static,
    City text static,
    State text static,
    Zip text static,
    Email  text static,
    Phone text static,
    OverallAssets double,
   PRIMARY KEY (id,UpdateDate)
); 

select * from user is working fine.

select * from user where partition key is also working fine.

But if I am putting non partition key in where clause getting below error.What can be the reason ?

ReadFailure: Error from server: code=1300 [Replica(s) failed to execute 
read] message="Operation failed - received 0 responses and 1 failures" info=
{'failures': 1, 'received_responses': 0, 'required_responses': 1, 
'consistency': 'ONE'}

回答1:


select * from user where CustID =0 allow filtering;

In Cassandra you need to take a query-based modeling approach. The best way to solve this problem is with a table that is specifically designed to serve that query.

CREATE TABLE users_by_custid (
    id text,
    CustID int,
    UpdateDate date,
    DateOfBirth date static,
    Gender text static,
    Address text static,
    City text static,
    State text static,
    Zip text static,
    Email  text static,
    Phone text static,
    OverallAssets double,
   PRIMARY KEY (cust_id,id,UpdateDate)
); 

That will work, it will distribute well, and it won't require the full table scans that accompany ALLOW FILTERING.

Yes I am doing cqlsh --connect-timeout=100000000 --request-timeout=10000000000

I can't warn you against doing this enough. Those timeout defaults exist for a reason. They protect your cluster/nodes from tipping over due to bad performing queries. When you are faced with a problem and tempted to increase the query timeouts, take a closer look at your query and see if there's a better way to build it.




回答2:


You are using allow filtering. Be careful. Executing this query with allow filtering might not be a good idea as it can use a lot of your computing resources and Might not return any result because of timeout. Don't use allow filtering in production Read the datastax doc about using ALLOW FILTERING

https://docs.datastax.com/en/cql/3.3/cql/cql_reference/select_r.html?hl=allow,filter

Instead of using allow filtering create materialized view or index.

Check this link about creating and using materialized view : https://www.datastax.com/dev/blog/new-in-cassandra-3-0-materialized-views

Check this link about creating and using index : http://docs.datastax.com/en/cql/3.1/cql/cql_reference/create_index_r.html

When not to use an index
Do not use an index in these situations:

  • On high-cardinality columns because you then query a huge volume of records for a small number of results. See Problems using a high-cardinality column index below.
  • In tables that use a counter column On a frequently updated or deleted column. See Problems using an index on a frequently updated or deleted column below.
  • To look for a row in a large partition unless narrowly queried. See Problems using an index to look for a row in a large partition unless narrowly queried below.

Source : http://docs.datastax.com/en/cql/3.1/cql/ddl/ddl_when_use_index_c.html



来源:https://stackoverflow.com/questions/43367076/cassandra-cqlsh-not-working-with-where-clause-on-non-partition-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!