Repository: cassandra Updated Branches: refs/heads/trunk e93977310 -> 30a704e01
Fix queries on static compact tables patch by slebresne; reviewed by iamaleskey for CASSANDRA-10093 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/23503205 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/23503205 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/23503205 Branch: refs/heads/trunk Commit: 2350320501bcd26085181b929f4718cb12d08b41 Parents: df65a6c Author: Sylvain Lebresne <sylv...@datastax.com> Authored: Mon Aug 17 15:00:41 2015 +0200 Committer: Sylvain Lebresne <sylv...@datastax.com> Committed: Tue Aug 18 09:04:24 2015 +0200 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../cql3/restrictions/StatementRestrictions.java | 11 ++++++++++- .../cassandra/cql3/statements/SelectStatement.java | 5 ++++- src/java/org/apache/cassandra/db/Clustering.java | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/23503205/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index b4b568c..54a6a07 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 3.0.0-beta1 + * Fix query on static compact tables (CASSANDRA-10093) * Fix race during construction of commit log (CASSANDRA-10049) * Add option to only purge repaired tombstones (CASSANDRA-6434) * Change authorization handling for MVs (CASSANDRA-9927) http://git-wip-us.apache.org/repos/asf/cassandra/blob/23503205/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java b/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java index 1a3b083..36f11ad 100644 --- a/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java +++ b/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java @@ -35,6 +35,7 @@ import org.apache.cassandra.dht.*; import org.apache.cassandra.exceptions.InvalidRequestException; import org.apache.cassandra.service.StorageService; import org.apache.cassandra.utils.ByteBufferUtil; +import org.apache.cassandra.utils.btree.BTreeSet; import static org.apache.cassandra.cql3.statements.RequestValidations.checkFalse; import static org.apache.cassandra.cql3.statements.RequestValidations.checkNotNull; @@ -478,6 +479,12 @@ public final class StatementRestrictions */ public NavigableSet<Clustering> getClusteringColumns(QueryOptions options) throws InvalidRequestException { + // If this is a names command and the table is a static compact one, then as far as CQL is concerned we have + // only a single row which internally correspond to the static parts. In which case we want to return an empty + // set (since that's what ClusteringIndexNamesFilter expects). + if (cfm.isStaticCompactTable()) + return BTreeSet.empty(cfm.comparator); + return clusteringColumnsRestrictions.valuesAsClustering(options); } @@ -513,7 +520,9 @@ public final class StatementRestrictions */ public boolean isColumnRange() { - // For static compact tables we need to ignore the fake clustering column. + // For static compact tables we want to ignore the fake clustering column (note that if we weren't special casing, + // this would mean a 'SELECT *' on a static compact table would query whole partitions, even though we'll only return + // the static part as far as CQL is concerned. This is thus mostly an optimization to use the query-by-name path). int numberOfClusteringColumns = cfm.isStaticCompactTable() ? 0 : cfm.clusteringColumns().size(); // it is a range query if it has at least one the column alias for which no relation is defined or is not EQ. return clusteringColumnsRestrictions.size() < numberOfClusteringColumns http://git-wip-us.apache.org/repos/asf/cassandra/blob/23503205/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java index 9acbb35..01ce8e6 100644 --- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java @@ -484,7 +484,10 @@ public class SelectStatement implements CQLStatement else { NavigableSet<Clustering> clusterings = getRequestedRows(options); - if (clusterings.isEmpty() && !selection.containsStaticColumns()) // in case of IN () for the last column of the key + // We can have no clusterings if either we're only selecting the static columns, or if we have + // a 'IN ()' for clusterings. In that case, we still want to query if some static columns are + // queried. But we're fine otherwise. + if (clusterings.isEmpty() && queriedColumns.fetchedColumns().statics.isEmpty()) return null; return new ClusteringIndexNamesFilter(clusterings, isReversed); http://git-wip-us.apache.org/repos/asf/cassandra/blob/23503205/src/java/org/apache/cassandra/db/Clustering.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/Clustering.java b/src/java/org/apache/cassandra/db/Clustering.java index a29ce65..2fb92d9 100644 --- a/src/java/org/apache/cassandra/db/Clustering.java +++ b/src/java/org/apache/cassandra/db/Clustering.java @@ -134,6 +134,7 @@ public class Clustering extends AbstractClusteringPrefix public void serialize(Clustering clustering, DataOutputPlus out, int version, List<AbstractType<?>> types) throws IOException { assert clustering != STATIC_CLUSTERING : "We should never serialize a static clustering"; + assert clustering.size() == types.size() : "Invalid clustering for the table: " + clustering; ClusteringPrefix.serializer.serializeValuesWithoutSize(clustering, out, version, types); }