使用TEXT作为主键时是否有性能损失? [英] Are there any performance penalties when using a TEXT as a Primary Key?

查看:211
本文介绍了使用TEXT作为主键时是否有性能损失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果是,如果我想要一个唯一的TEXT字段,数据模型会是什么样子?

If yes, what would the data model look like if I want to have a unique TEXT field?

推荐答案

无论使用何种数据类型,Cassandra都会将磁盘上的所有数据(包括主键值)存储为十六进制字节数组。在性能方面,主键的数据类型真的没有关系。

No. Regardless of data type used, Cassandra stores all data on disk (including primary key values) as hex byte arrays. In terms of performance, the datatype of the primary key really doesn't matter.

唯一的情况是它是重要的,是在令牌/节点分布。这是因为12345作为文本生成的令牌将不同于为 12345 生成的令牌作为bigint :

The only case where it would matter, is in token/node distribution. This is because the generated token for "12345" as text will be different from the token generated for 12345 as a bigint:

aploetz@cqlsh:stackoverflow> CREATE TABLE textaskey (key text PRIMARY KEY, value text);
aploetz@cqlsh:stackoverflow> CREATE TABLE longaskey (key bigint PRIMARY KEY, value text);
aploetz@cqlsh:stackoverflow> INSERT INTO textaskey (key, value) VALUES ('12345','12345');
aploetz@cqlsh:stackoverflow> INSERT INTO longaskey (key, value) VALUES (12345,'12345');
aploetz@cqlsh:stackoverflow> SELECT token(key),value FROM textaskey ;

 token(key)          | value
---------------------+-------
 2375712675693977547 | 12345

(1 rows)
aploetz@cqlsh:stackoverflow> SELECT token(key),value FROM longaskey;

 token(key)          | value
---------------------+-------
 3741197147323682197 | 12345

(1 rows)

但是即使在这个例子中,不会比其他更快/不同。

But even in this example, one shouldn't perform faster/different than the other.

这篇关于使用TEXT作为主键时是否有性能损失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆