我最初的想法是该约束是由于对内存和网络的影响来获取集合,因为可以在限制条件下一次返回多个集合。但是,我发现如果仅通过指定分区键的限制较少,查询就可以工作。
我的测试数据(在 Cassandra 3.7 上):
cqlsh:test> create table mytable(X text, Y text, Z text, mylist list<int>, primary key (X,Y));
cqlsh:test> insert into mytable (X,Y,Z,mylist) values('x','y1','z1',[1,2,3]);
cqlsh:test> insert into mytable (X,Y,Z,mylist) values('x','y2','z2',[4,5,6]);
cqlsh:test> select x,y,z from mytable where x = 'x' and y in ('y1');
x | y | z
---+----+----
x | y1 | z1
(1 rows)
cqlsh:test> select * from mytable where x = 'x' and y in ('y1');
InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot restrict clustering columns by IN relations when a collection is selected by the query"
cqlsh:test> select * from mytable where x = 'x';
x | y | mylist | z
---+----+-----------+----
x | y1 | [1, 2, 3] | z1
x | y2 | [4, 5, 6] | z2
(2 rows)
底层 sstable 转储:
$ sstabledump mb-1-big-Data.db
[
{
"partition" : {
"key" : [ "x" ],
"position" : 0
},
"rows" : [
{
"type" : "row",
"position" : 15,
"clustering" : [ "y1" ],
"liveness_info" : { "tstamp" : "2016-09-13T08:14:33.172799Z" },
"cells" : [
{ "name" : "z", "value" : "z1" },
{ "name" : "mylist", "deletion_info" : { "marked_deleted" : "2016-09-13T08:14:33.172798Z", "local_delete_time" : "2016-09-13T08:14:33Z" } },
{ "name" : "mylist", "path" : [ "1a1a0760-798a-11e6-851a-e3954ecad15b" ], "value" : "1" },
{ "name" : "mylist", "path" : [ "1a1a0761-798a-11e6-851a-e3954ecad15b" ], "value" : "2" },
{ "name" : "mylist", "path" : [ "1a1a0762-798a-11e6-851a-e3954ecad15b" ], "value" : "3" }
]
},
{
"type" : "row",
"position" : 99,
"clustering" : [ "y2" ],
"liveness_info" : { "tstamp" : "2016-09-13T08:14:49.772718Z" },
"cells" : [
{ "name" : "z", "value" : "z2" },
{ "name" : "mylist", "deletion_info" : { "marked_deleted" : "2016-09-13T08:14:49.772717Z", "local_delete_time" : "2016-09-13T08:14:49Z" } },
{ "name" : "mylist", "path" : [ "23fefce0-798a-11e6-851a-e3954ecad15b" ], "value" : "4" },
{ "name" : "mylist", "path" : [ "23fefce1-798a-11e6-851a-e3954ecad15b" ], "value" : "5" },
{ "name" : "mylist", "path" : [ "23fefce2-798a-11e6-851a-e3954ecad15b" ], "value" : "6" }
]
}
]
}
]
正如您所见,集合与非主键列并没有真正的不同,除了在将其返回给客户端之前需要进行聚合。我想知道这是否是对旧的 thrift 实现的限制,并且即使没有明显的原因不能做到这一点,也会被延续。