I'm creating a table in cassandra for users. Users have both a unique user_id
and a unique display_name
.
My table currently resembles:
create table user (user_id text primary key,
display_name text,
joined timestamp,
last_seen timestamp,
...);
When a new user creates an account I need to check if the display name they enter is already someone else's. What's the fastest way I can do this?
This project is primarily a learning project for me, I want to experiment with some NoSQL concepts in a semi-real-world situation.
My own thoughts are that using two tables like this:
create table user (user_id text primary key,
display_name text,
joined timestamp,
last_seen timestamp,
...);
create table user_by_display_name (display_name text primary key, user_id text);
And then looking up in user_by_display_name
for existence of a username will be faster than looking up in user where display_name = ?
. Is this a correct assumption?
I feel that two lookups on primary keys, user_by_display_name where display_name = ?
and then another lookup using the user_id
in user
might be slower than the single user where display_name = ?
lookup if I need the information about that user.