【问题标题】:Secondary indexes on composite keys in cassandracassandra中复合键的二级索引
【发布时间】:2014-03-13 09:23:00
【问题描述】:

我在 cassandra 中有这张桌子

CREATE TABLE global_product_highlights (
  deal_id text,
  product_id text,
  highlight_strength double,
  category_id text,
  creation_date timestamp,
  rank int,
  PRIMARY KEY (deal_id, product_id, highlight_strength)
)

当我在 Golang 中触发以下查询时

err = session.Query("select product_id from global_product_highlights where category_id=? order by highlight_strength DESC",default_category).Scan(&prodId_array)

我得到 ERROR : ORDER BY with 2ndary index is not supported.

我在 category_id 上有一个索引。

我不完全了解二级索引是如何应用于 cassandra 中的复合键的。

如果有人能解释并纠正这一点,不胜感激。

【问题讨论】:

    标签: go cassandra


    【解决方案1】:

    Cassandra 中的ORDER BY 子句仅适用于您的第一个集群列(主键中的第二列),在本例中是您的 product_id。 This DataStax doc 声明:

    查询复合主键和排序结果 ORDER BY 子句 只能选择一列。该列必须是第二个 复合 PRIMARY KEY 中的列。

    因此,如果您想让您的表格按 highlight_strength 排序,那么您需要将该字段设置为第一个聚类列。

    【讨论】:

      猜你喜欢
      • 2013-07-25
      • 1970-01-01
      • 2018-07-01
      • 1970-01-01
      • 2020-03-20
      • 2012-12-17
      • 2018-06-23
      • 2016-06-29
      • 2013-09-30
      相关资源
      最近更新 更多