cassandra - 实体化 View 中的排序依据不对结果进行排序

标签 cassandra cassandra-3.0 scylla

我有一个结构如下的表:

CREATE TABLE kaefko.se_vi_f55dfeebae00d2b3 (
value text PRIMARY KEY,
id text,
popularity bigint);

数据看起来像这样:

value  | id               | popularity
--------+------------------+------------
rally  | 4eff16cb91f96cd6 |          2
reddit | 11aa39686ed66ba5 |          3
red    | 552d7e95af481415 |          1
really | 756bfa499965863c |          1
right  | c5850c6b08f7966b |          1
redis  | 7f1d251f399442d7 |          1

我创建了一个物化 View ,它应该按照受欢迎程度从大到小对这些值进行排序:

CREATE MATERIALIZED VIEW kaefko.se_vi_f55dfeebae00d2b3_by_popularity AS
SELECT *
FROM kaefko.se_vi_f55dfeebae00d2b3
WHERE popularity IS NOT null
PRIMARY KEY (value, popularity)
WITH CLUSTERING ORDER BY (popularity DESC);

但是物化 View 中的数据是这样的:

value  | popularity | id
--------+------------+------------------
rally  |          2 | 4eff16cb91f96cd6
reddit |          3 | 11aa39686ed66ba5
really |          1 | 756bfa499965863c
right  |          1 | c5850c6b08f7966b
redis  |          1 | 7f1d251f399442d7

如您所见,有两个主要问题:

  1. 数据未按照物化 View 中的定义排序
  2. 物化 View 中只有所有数据的一部分

我在 Cassandra 方面不是很有经验,我已经花了几个小时试图找出发生这种情况但无济于事的原因。有人可以帮我吗?谢谢<3

__

我使用的是 ScyllaDB 4.1.9-0,cqlsh 显示:

[cqlsh 5.0.1 | Cassandra 3.0.8 | CQL spec 3.3.1 | Native protocol v4]

最佳答案

Alex 的评论 100% 正确,顺序在分区内。

PRIMARY KEY (value, popularity)
WITH CLUSTERING ORDER BY (popularity DESC);

这意味着受欢迎程度的排序仅针对“值”字段相同的值进行降序 - 如果我要更改您用来显示示例的数据,您将得到以下内容:

value  | popularity | id
--------+------------+------------------
rally  |          3 | 4eff16cb91f96cd6
rally  |          2 | 11aa39686ed66ba5
really |          3 | 756bfa499965863c
really |          2 | c5850c6b08f7966b
really |          1 | 7f1d251f399442d7

顺序是基于每个分区键的,而不是全局排序的。

关于cassandra - 实体化 View 中的排序依据不对结果进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65105732/

相关文章:

Cassandra - 不同表中的相同分区键 - 何时正确?

Cassandra Vnodes和 token 范围

hadoop - Hadoop与数据库有何不同?

python - 如何将字典绑定(bind)为准备好的查询参数?

cassandra - memtable_flush_writer意义及用途

斯库拉数据库 : Scylla write latency increasing over the time for continuous batch write ingestion

cassandra - 无法连接到本地主机上的 Cassandra

java - 使用 MetricsServlet 获取 Cassandra 中的指标

cassandra - sstableexpiredblockers : what to do having blocking SSTables in Cassandra?

database - 如何将 Scylla DB 中的计数器列重置为零?