Cassandra 中的列太多
Too many columns in Cassandra
我在 Cassandra 的 table 中有 20 列。执行
是否会对性能产生影响
select * from table where partitionKey = 'test';
我无法理解link,
https://wiki.apache.org/cassandra/CassandraLimitations
1) 在 Cassandra table 中有太多列(比如 20)会产生什么后果?
除非分区上有很多行,否则我看不到 20 列的影响。正如您链接的文档中所述:
The maximum number of cells (rows x columns) in a single partition is 2 billion.
因此,除非您期望单个分区中有超过 1 亿行,否则我不明白为什么 20 列会成为问题。请记住,Cassandra 是一家专栏商店。这种指定意味着 Cassandra 可以在每个分区中存储大量列。
话虽如此,我个人建议每个分区不要超过 100 MB。以后维修时流媒体可能会出问题。
===============================
回复您的评论。请记住,分区和行在 Cassandra 中是两种不同的东西。如果没有聚类列,则分区仅等于一行。例如,看看这个 table 创建和我们插入的值,然后看看 sstabledump:
create TABLE tt2 ( foo int , bar int , mar int , PRIMARY KEY (foo , bar )) ;
insert INTO tt2 (foo , bar , mar ) VALUES ( 1, 2, 3) ;
insert INTO tt2 (foo , bar , mar ) VALUES ( 1, 3, 4) ;
sstable转储:
./cassandra/tools/bin/sstabledump ~/cassandra/data/data/tk/tt2-1386f69005bd11e89c0bbfb5c1157523/mc-1-big-Data.db
[
{
"partition" : {
"key" : [ "1" ],
"position" : 0
},
"rows" : [
{
"type" : "row",
"position" : 32,
"clustering" : [ "2" ],
"liveness_info" : { "tstamp" : "2018-01-30T12:57:36.362483Z" },
"cells" : [
{ "name" : "mar", "value" : 3 }
]
},
{
"type" : "row",
"position" : 32,
"clustering" : [ "3" ],
"liveness_info" : { "tstamp" : "2018-01-30T12:58:03.538482Z" },
"cells" : [
{ "name" : "mar", "value" : 4 }
]
}
]
}
]
此外,如果您使用 -d
选项,它可能会让您更容易看到内部表示。如您所见,对于同一个分区,我们有 2 个不同的行:
./cassandra/tools/bin/sstabledump -d ~/cassandra/data/data/tk/tt2-1386f69005bd11e89c0bbfb5c1157523/mc-1-big-Data.db
[1]@0 Row[info=[ts=1517317056362483] ]: 2 | [mar=3 ts=1517317056362483]
[1]@32 Row[info=[ts=1517317083538482] ]: 3 | [mar=4 ts=1517317083538482]
我在 Cassandra 的 table 中有 20 列。执行
是否会对性能产生影响select * from table where partitionKey = 'test';
我无法理解link,
https://wiki.apache.org/cassandra/CassandraLimitations
1) 在 Cassandra table 中有太多列(比如 20)会产生什么后果?
除非分区上有很多行,否则我看不到 20 列的影响。正如您链接的文档中所述:
The maximum number of cells (rows x columns) in a single partition is 2 billion.
因此,除非您期望单个分区中有超过 1 亿行,否则我不明白为什么 20 列会成为问题。请记住,Cassandra 是一家专栏商店。这种指定意味着 Cassandra 可以在每个分区中存储大量列。
话虽如此,我个人建议每个分区不要超过 100 MB。以后维修时流媒体可能会出问题。
===============================
回复您的评论。请记住,分区和行在 Cassandra 中是两种不同的东西。如果没有聚类列,则分区仅等于一行。例如,看看这个 table 创建和我们插入的值,然后看看 sstabledump:
create TABLE tt2 ( foo int , bar int , mar int , PRIMARY KEY (foo , bar )) ;
insert INTO tt2 (foo , bar , mar ) VALUES ( 1, 2, 3) ;
insert INTO tt2 (foo , bar , mar ) VALUES ( 1, 3, 4) ;
sstable转储:
./cassandra/tools/bin/sstabledump ~/cassandra/data/data/tk/tt2-1386f69005bd11e89c0bbfb5c1157523/mc-1-big-Data.db
[
{
"partition" : {
"key" : [ "1" ],
"position" : 0
},
"rows" : [
{
"type" : "row",
"position" : 32,
"clustering" : [ "2" ],
"liveness_info" : { "tstamp" : "2018-01-30T12:57:36.362483Z" },
"cells" : [
{ "name" : "mar", "value" : 3 }
]
},
{
"type" : "row",
"position" : 32,
"clustering" : [ "3" ],
"liveness_info" : { "tstamp" : "2018-01-30T12:58:03.538482Z" },
"cells" : [
{ "name" : "mar", "value" : 4 }
]
}
]
}
]
此外,如果您使用 -d
选项,它可能会让您更容易看到内部表示。如您所见,对于同一个分区,我们有 2 个不同的行:
./cassandra/tools/bin/sstabledump -d ~/cassandra/data/data/tk/tt2-1386f69005bd11e89c0bbfb5c1157523/mc-1-big-Data.db
[1]@0 Row[info=[ts=1517317056362483] ]: 2 | [mar=3 ts=1517317056362483]
[1]@32 Row[info=[ts=1517317083538482] ]: 3 | [mar=4 ts=1517317083538482]