Apache Cassandra 中的复合索引

发布于 2024-10-10 06:42:56 字数 1022 浏览 0 评论 0原文

我正在尝试设置一个 cassandra 列族,其中一些列上有二级索引,在读回数据时我需要进行过滤。在我最初的测试中,当我一起使用多个索引时,速度会变慢。以下是我当前的配置方式(通过 cassandra-cli):

update column family bulkdata with comparator=UTF8Type and column_metadata=[{column_name: test_field, validation_class: UTF8Type}, {column_name: create_date, validation_class: LongType, index_type: KEYS}, {column_name: domain, validation_class: UTF8Type, index_type: KEYS}];

我想获取 create_date > 的所有数据somevalue1 和column_name = somevalue2。我为我的客户使用 pycassa 执行以下操作:

  domain_expr = create_index_expression('domain', 'whatever.com')
  cd_expr = create_index_expression('create_date', 1293650000, GT)
  clause = create_index_clause([domain_expr, cd_expr], count=10000)
  for key, item in col_fam.get_indexed_slices(clause):
    ...

当然,这是 SQL 中的一个常见错误,通常必须根据查询需求创建一个复合索引。不过,我对卡桑德拉很陌生,所以我不知道这样的东西是否需要甚至存在。

我与 cassandra 的交互将包括大量写入、大量读取和更新。我已经设置了索引,认为它们是在这里做的正确的事情,但也许我完全错了。我对任何建立高性能系统的想法感兴趣,无论是否有我的索引设置。

哦,这是在 cassandra 0.7.0-rc3 上

I am trying to set up a cassandra column family with secondary indexes on a few columns I will need to filter by when reading data back out. In my initial testing, when I use multiple indexes together, things slow down. Here is how I have it configured currently (via cassandra-cli):

update column family bulkdata with comparator=UTF8Type and column_metadata=[{column_name: test_field, validation_class: UTF8Type}, {column_name: create_date, validation_class: LongType, index_type: KEYS}, {column_name: domain, validation_class: UTF8Type, index_type: KEYS}];

I want to get all data where create_date > somevalue1 and column_name = somevalue2. Using pycassa for my client I do the following:

  domain_expr = create_index_expression('domain', 'whatever.com')
  cd_expr = create_index_expression('create_date', 1293650000, GT)
  clause = create_index_clause([domain_expr, cd_expr], count=10000)
  for key, item in col_fam.get_indexed_slices(clause):
    ...

This is a common mistake in SQL of course, where one would normally have to create a compound index, based on the query needs. I'm quite new to cassandra though, so I don't know if such a thing is required or even exists.

My interactions with cassandra will include large numbers of writes, and large numbers of reads and updates. I have set up the indexes figuring they were the right thing to do here, but perhaps I am completely wrong. I'd be interested in any ideas for setting up a performant system, with my index setup or without.

oh, and this is on cassandra 0.7.0-rc3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜宝宝 2024-10-17 06:42:56

本机 Cassandra 二级索引有一些限制。根据 datastax 文档,它们不应该用于具有高基数(太多唯一值)的列。您正在索引的 create_date 列似乎将具有高基数。此外,原生 Cassandra 索引支持中不存在复合索引之类的东西。

如需更深入的报道,您可以访问我的博客文章
http://pkghosh.wordpress.com/2011/03/02/cassandra-secondary -index-patterns/

普拉纳布

Native Cassandra secondary indexes have some limitations. They are not supposed to be used for columns with high cardinality (too many unique values), according to datastax documentation. It seems like the create_date column you are indexing on will have high cardinality. Also, there is no such thing as compound index in native Cassandra index support.

For more in depth coverage, you can visit my blog post
http://pkghosh.wordpress.com/2011/03/02/cassandra-secondary-index-patterns/

Pranab

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文