Merge branch 'cassandra-1.2' into trunk
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/abea32e1 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/abea32e1 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/abea32e1 Branch: refs/heads/trunk Commit: abea32e19f6df203286bffafa86ee93331aaffb3 Parents: 79fe644 b0f7bab Author: Sylvain Lebresne <[email protected]> Authored: Mon Jul 22 14:03:02 2013 +0200 Committer: Sylvain Lebresne <[email protected]> Committed: Mon Jul 22 14:03:02 2013 +0200 ---------------------------------------------------------------------- CHANGES.txt | 2 + .../cql3/statements/SelectStatement.java | 98 ++++++++++++++------ 2 files changed, 71 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/abea32e1/CHANGES.txt ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/abea32e1/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java ---------------------------------------------------------------------- diff --cc src/java/org/apache/cassandra/cql3/statements/SelectStatement.java index 958a114,2a2b33a..ce0d50b --- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java @@@ -367,17 -325,46 +367,44 @@@ public class SelectStatement implement // to account for the grouping of columns. // Since that doesn't work for maps/sets/lists, we now use the compositesToGroup option of SliceQueryFilter. // But we must preserve backward compatibility too (for mixed version cluster that is). - int multiplier = cfDef.isCompact ? 1 : (cfDef.metadata.size() + 1); int toGroup = cfDef.isCompact ? -1 : cfDef.columns.size(); - ColumnSlice slice = new ColumnSlice(getRequestedBound(Bound.START, variables), - getRequestedBound(Bound.END, variables)); + List<ByteBuffer> startBounds = getRequestedBound(Bound.START, variables); + List<ByteBuffer> endBounds = getRequestedBound(Bound.END, variables); + assert startBounds.size() == endBounds.size(); - if (slice.isAlwaysEmpty(cfDef.cfm.comparator, isReversed)) - return null; + // The case where startBounds == 1 is common enough that it's worth optimizing + ColumnSlice[] slices; + if (startBounds.size() == 1) + { + ColumnSlice slice = new ColumnSlice(startBounds.get(0), endBounds.get(0)); + if (slice.isAlwaysEmpty(cfDef.cfm.comparator, isReversed)) + return null; + slices = new ColumnSlice[]{slice}; + } + else + { + // The IN query might not have listed the values in comparator order, so we need to re-sort + // the bounds lists to make sure the slices works correctly + Comparator<ByteBuffer> cmp = isReversed ? cfDef.cfm.comparator.reverseComparator : cfDef.cfm.comparator; + Collections.sort(startBounds, cmp); + Collections.sort(endBounds, cmp); + + List<ColumnSlice> l = new ArrayList<ColumnSlice>(startBounds.size()); + for (int i = 0; i < startBounds.size(); i++) + { + ColumnSlice slice = new ColumnSlice(startBounds.get(i), endBounds.get(i)); + if (!slice.isAlwaysEmpty(cfDef.cfm.comparator, isReversed)) + l.add(slice); + } + if (l.isEmpty()) + return null; + slices = l.toArray(new ColumnSlice[l.size()]); + } - SliceQueryFilter filter = new SliceQueryFilter(new ColumnSlice[]{slice}, + SliceQueryFilter filter = new SliceQueryFilter(slices, isReversed, - getLimit(), - toGroup, - multiplier); + limit, + toGroup); return filter; } else
