Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Login cassandra数据库中的登录功能_Login_Cassandra_Primary Key - Fatal编程技术网

Login cassandra数据库中的登录功能

Login cassandra数据库中的登录功能,login,cassandra,primary-key,Login,Cassandra,Primary Key,我有一个以userId作为主键的用户表(列族),它还有其他详细信息,如emailId、密码、用户名等 我的疑问是,当用户使用emailId登录时,如何在表中查找密码,因为我的主键是userId而不是emailId 还是创建emailId作为主键更好 或者用于将userId与emailId映射的附加表?假设您的Cassandra版本支持物化视图(3.x),下面是可以轻松完成的操作 假设您的原始表模式如下,userId是主键 create table userdetails_by_id (user

我有一个以userId作为主键的用户表(列族),它还有其他详细信息,如emailId、密码、用户名等

我的疑问是,当用户使用emailId登录时,如何在表中查找密码,因为我的主键是userId而不是emailId

还是创建emailId作为主键更好


或者用于将userId与emailId映射的附加表?

假设您的Cassandra版本支持物化视图(3.x),下面是可以轻松完成的操作

假设您的原始表模式如下,userId是主键

create table userdetails_by_id 
(userId text primary key,
 emailId text,
 password text,
 username text);
创建一个物化视图,其中emailId将是主键,并包含主表中的所有其他字段。这是它的定义

create materialized view userdetails_by_emailid
as select 
userId,
emailId,
password,
username
from userdetails_by_id 
where userId is not null and emailId is not null
primary key (emailId, userId);

现在,当查询针对userId时,可以将其路由到主表,而针对emailId的查询可以路由到物化视图。这样,Cassandra将保持数据同步,并且维护两个表不需要额外的应用程序代码。

创建额外的映射表(emailId到userId)需要查询两个表。这违背了卡桑德拉的设计原则。尽量减少需要触发的查询。在您的情况下,需要使用emailId作为主键的表。

您使用的是哪个版本的Cassandra?