[Question posted by a user on YugabyteDB Community Slack]
Question about UNIQUE keyword. I can create an index with unique keyword inside, like:
CREATE unique INDEX warehouse_idx ON orders (warehouse_id);
But I do not see this opportunity in the documentation. This is confusing.
There is an example on creating the index on the docs page: https://docs.yugabyte.com/preview/api/ycql/ddl_create_index/#create-a-table-with-a-unique-index
Related
I want to read all the Items of this table where postedby attribute value should equals to "Peter"
partition key in this table is postid.
I want to access this data using Node Js but not getting exact documentation regarding this question.
Any help will be appreciated .
If you want to frequently query by a value it’s best to make that your partition key, either in the base table or in a GSI.
What good is a post ID doing as your PK? Maybe have the PK be the poster and the SK be the timestamp. Now you’ve got your data modeled in the way you’re likely to retrieve it.
Forget what you learned with relational databases. Id suggest spending an hour watching YouTube on DynamoDB schema designs.
Let's say I'm implementing a forum system (let's think something like Reddit or even SO) that's backed by Cassandra.
A post has multiple fields, like content, timestamp, etc, plus a rating (upvotes plus downvotes). Posts are backed by a POSTS table. Let's assume for the sake of the argument that I don't care to know which specific users did upvote or downvote, I just care about a post's total rating.
I'm wondering if there's any advantage in storing the ratings in a RATINGS (post_id, rating) table instead of just having it as a field in POSTS, given that there are going to be lots of upvotes / downvotes happening all the time.
Given Cassandra's architecture, what would be the ins and outs of choosing one approach over the other?
Putting rating in another table will not make sense as it appears you will be using the same partition key for both tables (POSTS and RATINGS). You can always get ratings from POSTS table. I don't see any benefit in creating RATINGS table.
I have seen this screenshot about a data modeling in cassandra for an shopping cart.
Can anyone explain me two questions?
Q1: why is cart_id a UUID and user_id a TEXT ?
Q2: why I need items_by_name when items_by_id table exists ?
If you see the explanation in the above diagram, each table has a marker text on arrows which says for what queries these tables will be required. In Cassandra, you create schema based on your queries, which are required by application. So that answers your second question, if your application has a query like Q3 then you need to create that table. Otherwise no way you can find items by name. For second question it is more of architectural decision what kind of key you want.
We are trying to store user answers on questions. Answer is id based. When user comes to site we need to get all question ids to know that he had answered. Question count can be about 50000 or more. Currently, we are storing data in sql server using appendable blob (varbinary(max)). But we are searching database that can handle that situation. Casandra can give us non blob scheme and master - master replication. What is right way to store it in casandra? I known lists are not recommended for such situation. Does separate table give us suitable performance (<20-30ms) with composite key?
I'm not 100% sure that I understand how you'll fetch the data, but usually, if you have only one collection-like column in your table, then you can always implement it as an additional column as clustering column - this will solve a problem with accessing the part of the answers, etc. - when you have answer ID as clustering column, you can fetch only range of the answers, but when you use set, then you need to fetch everything...
For example, if you have table like this:
create table answers (
user_id text primary key,
answers set<int>
)
it could be always converted from collection to following:
create table answers (
user_id text,
answer_id int,
primary key (user_id, answer_id));
but actual table structure will depend on how you're performing queries for this data - this is primary requirement for data modeling for Cassandra.
P.S. I recommend to take DS220 course on DataStax Academy, to learn more about data modellng, or grab 3rd edition of Cassandra book, that was released recently - it has good chapter on data modeling.
Is there a way for Cassandra's Thrift interface to know in advance whether a particular client query will use a compound keys defined table (CQL3)? How can you know what the schema is for the table?
Cassandra stores the schema information in some system tables. You could query those to get the schema information that indicates that the rows have a compound primary key.
But you might want to reconsider why you want to do this. Your application program should know the schema of the tables it manipulates; it should already know what tables it uses and what their primary key is.
Check out this question and the answer for details on how to determine the schema from system tables.
Anyways as Raedwald already said, you should probably ask twice why you'd want to do this.