[ https://issues.apache.org/jira/browse/CASSANDRA-13186?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15970410#comment-15970410 ]
Aleksandr Sorokoumov commented on CASSANDRA-13186: -------------------------------------------------- In order to better understand the issue, I have been reading how secondary indexes work and would like to clarify one point before submitting the patch. >From the documentation >(http://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlCreateIndex.html): {quote} Cassandra supports creating an index on most columns, excluding counter columns but including a clustering column of a compound primary key or on the partition (primary) key itself {quote} It is not clear to me how a secondary index on the whole partition key (not just a component) works. AFAIU the index is implemented by maintaining a hidden table where the indexed column is the primary key and the partition key of the original table is the value. (Source: https://www.datastax.com/dev/blog/cassandra-native-secondary-index-deep-dive). In the hypothetical case, if the column is both the primary key and the native secondary index, both columns of the hidden table would contain the same values. > Create index fails if the primary key is included, but docs claim it is > supported > --------------------------------------------------------------------------------- > > Key: CASSANDRA-13186 > URL: https://issues.apache.org/jira/browse/CASSANDRA-13186 > Project: Cassandra > Issue Type: Bug > Components: CQL > Reporter: Ariel Weisberg > Assignee: Aleksandr Sorokoumov > > {noformat} > cqlsh:foo> CREATE TABLE users ( > ... userid text PRIMARY KEY, > ... first_name text, > ... last_name text, > ... emails set<text>, > ... top_scores list<int>, > ... todo map<timestamp, text> > ... ); > cqlsh:foo> create index bar on foo.users (userid, last_name); > InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot > create secondary index on partition key column userid" > {noformat} > {quote} > <beobal> yes, it's a bug in CreateIndexStatement. The check to enforce the PK > has only a single component is wrong > it considers each target in isolation, so it doesn't take into account that > you might be creating a custom index on a PK component + something else > {quote} > http://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlCreateIndex.html > {quote} > Cassandra supports creating an index on most columns, excluding counter > columns but including a clustering column of a compound primary key or on the > partition (primary) key itself. > {quote} -- This message was sent by Atlassian JIRA (v6.3.15#6346)