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

查看:25
本文介绍了使用 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天全站免登陆