This is an automated email from the ASF dual-hosted git repository. slebresne pushed a commit to branch cassandra-3.0 in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/cassandra-3.0 by this push: new 64c80f4 Accepts 2i queries with only static columns for KEYS index 64c80f4 is described below commit 64c80f4ef89f0cc88c15febed8c01eb07ae0a84e Author: Sylvain Lebresne <lebre...@gmail.com> AuthorDate: Mon Jun 29 16:27:01 2020 +0200 Accepts 2i queries with only static columns for KEYS index KEYS index can originally only be created on compact tables, which don't have static columns. However, through DROP COMPACT STORAGE, a previously compact table with a KEYS index will have its columns all be static, and queries of the 2i KEYS was rejected. This patch ensure the queries does went through in that case. Patch by Sylvain Lebresne, reviewed by Brandon Williams for CASSANDRA-15906 --- CHANGES.txt | 1 + .../cql3/restrictions/StatementRestrictions.java | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 7e1a4fd..d94041b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 3.0.21 + * Fix broken KEYS 2i queries after DROP COMPACT STORAGE (CASSANDRA-15906) * Add token to tombstone warning and error messages (CASSANDRA-15890) * Fixed range read concurrency factor computation and capped as 10 times tpc cores (CASSANDRA-15752) * Catch exception on bootstrap resume and init native transport (CASSANDRA-15863) diff --git a/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java b/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java index 84c6958..d7d6f48 100644 --- a/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java +++ b/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java @@ -21,6 +21,7 @@ import java.nio.ByteBuffer; import java.util.*; import com.google.common.base.Joiner; +import com.google.common.collect.Iterables; import com.google.common.collect.Iterators; import org.apache.cassandra.config.CFMetaData; @@ -37,6 +38,7 @@ import org.apache.cassandra.exceptions.InvalidRequestException; import org.apache.cassandra.index.Index; import org.apache.cassandra.index.SecondaryIndexManager; import org.apache.cassandra.net.MessagingService; +import org.apache.cassandra.schema.IndexMetadata; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.btree.BTreeSet; @@ -838,9 +840,18 @@ public final class StatementRestrictions "Select on indexed columns and with IN clause for the PRIMARY KEY are not supported"); // When the user only select static columns, the intent is that we don't query the whole partition but just // the static parts. But 1) we don't have an easy way to do that with 2i and 2) since we don't support index on - // static columns - // so far, 2i means that you've restricted a non static column, so the query is somewhat non-sensical. - checkFalse(selectsOnlyStaticColumns, "Queries using 2ndary indexes don't support selecting only static columns"); + // static columns so far, 2i means that you've restricted a non static column, so the query is somewhat + // non-sensical. + // Note: an exception is if the index is a KEYS one. Which can happen if the user had a KEYS index on + // a compact table, and subsequently DROP COMPACT STORAGE on that table. After which, the KEYS index will still + // work, but queries will effectively be only on now-static columns and we should let this work. + checkFalse(selectsOnlyStaticColumns && !hasKeysIndex(cfm), + "Queries using 2ndary indexes don't support selecting only static columns"); + } + + private boolean hasKeysIndex(CFMetaData cfm) + { + return Iterables.any(cfm.getIndexes(), i -> i.kind == IndexMetadata.Kind.KEYS); } /** --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org