“使用CQL3在Apache Cassandra中无法在PRIMARY KEY部分创建索引”错误

时间:2013-07-08 19:49:51

标签: apache cassandra cql3

我正在关注“Cassandra专家的CQL3”(http://www.datastax.com/dev/blog/cql3-for-cassandra-experts#comment-259613)文章。执行

CREATE TABLE playlists (
  id uuid,
  title text,
  album text,
  artist text,
  song_id uuid,
  PRIMARY KEY (id, title, album, artist)
);

工作正常。但是在试图运行时

CREATE INDEX ON playlists(artist);

我收到错误:

An error occurred when executing the SQL command:
CREATE INDEX ON playlists(artist)

Cannot create index on PRIMARY KEY part artist
‘CREATE INDEX ON playlists(artist)’

文章说它应该可以正常工作。这是一个错误还是我做错了什么?

我正在运行Cassandra 1.2.4并使用JDBC 1.2.5驱动程序连接到它。

2 个答案:

答案 0 :(得分:0)

您无法在分区键上创建索引,即复合键的任何列部分,因为它们是自动索引的。 那么为什么你需要在主键的一部分上创建索引?

答案 1 :(得分:0)

为了未来的到来,显然这是在后来的Cassandra版本中修复的。我在版本2.0.8.39和1.2.13.2中有相同的表,并且创建索引确实起作用而前者,但不是后者。

相关问题