i trying define cassandra tables following problem.
have following relations:
user (user_id) can see many adds (add_id).
add (add_id) can saw more 1 user.
and want make following querys in cassandra:
- given user (user_id) give me adds (add_id) user saw
- given add (add_id) give me users (user_id) saw add
the aproach took create 2 tables whith relations
create table adds_by_user ( user_id text, add_id text, primary key (user_id, add_id) ); create table user_by_add ( add_id text, user_id text, primary key (add_id, user_id) );
my algorithm following
given user_id:
- give me add_id user watched.
- for each add_id, give me user_id watched add_id
- for each user_id, give me add_id each user watched
another graphical way see is:
(one) user_id -> (many) add_id -> (many+) user_id -> (many++) add_id
the problems arises when have lot of relations , algorithm spends lot of time doing queries (despite fact each individual query done in 0.5 milliseconds or less, but there lot of them)
i using async queries
is there model can make queries faster?
is there model make algorithm make less queries , respect cassandra standards?
thanks!!
example of data model:
create table user_address_user( user_id text, address_id text, user_level2 text, address_level2 text, primary key((user_id), address_id, user_level2, address_level2) );
this table structure can seen as
map<user_id, sortedmap<address_id, sortedmap<user_level2, sortedset<address_level2>>>>
Comments
Post a Comment