cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject [2/7] git commit: Optimize name query performance in wide rows patch by rbranson; reviewed by jbellis for CASSANDRA-5966
Date Sun, 01 Sep 2013 02:36:17 GMT
Optimize name query performance in wide rows
patch by rbranson; reviewed by jbellis for CASSANDRA-5966


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/b14273b4
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/b14273b4
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/b14273b4

Branch: refs/heads/trunk
Commit: b14273b4352ac814946d8e1b9f9be479ddae8d0b
Parents: 1a50215
Author: Jonathan Ellis <jbellis@apache.org>
Authored: Sat Aug 31 20:35:19 2013 -0500
Committer: Jonathan Ellis <jbellis@apache.org>
Committed: Sat Aug 31 20:35:19 2013 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../db/columniterator/SSTableNamesIterator.java | 37 ++++++++++++++++----
 2 files changed, 31 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/b14273b4/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 777d0d1..1943217 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 1.2.10
+ * Optimize name query performance in wide rows (CASSANDRA-5966)
  * Upgrade metrics-core to version 2.2.0 (CASSANDRA-5947)
  * Add snitch, schema version, cluster, partitioner to JMX (CASSANDRA-5881)
  * Fix CqlRecordWriter with composite keys (CASSANDRA-5949)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/b14273b4/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java b/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java
index df28c46..40934d4 100644
--- a/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java
+++ b/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java
@@ -153,7 +153,7 @@ public class SSTableNamesIterator extends SimpleAbstractColumnIterator
implement
         List<OnDiskAtom> result = new ArrayList<OnDiskAtom>();
         if (indexList.isEmpty())
         {
-            readSimpleColumns(file, columns, result);
+            readSimpleColumns(sstable.metadata, file, columns, result);
         }
         else
         {
@@ -175,27 +175,37 @@ public class SSTableNamesIterator extends SimpleAbstractColumnIterator
implement
         iter = result.iterator();
     }
 
-    private void readSimpleColumns(FileDataInput file, SortedSet<ByteBuffer> columnNames,
List<OnDiskAtom> result) throws IOException
+    private void readSimpleColumns(CFMetaData metadata,
+                                   FileDataInput file,
+                                   SortedSet<ByteBuffer> columnNames,
+                                   List<OnDiskAtom> result)
+    throws IOException
     {
+        AbstractType<?> comparator = metadata.comparator;
         OnDiskAtom.Serializer atomSerializer = cf.getOnDiskSerializer();
+        ByteBuffer maximalColumnName = columnNames.last();
         int count = file.readInt();
-        int n = 0;
+
         for (int i = 0; i < count; i++)
         {
             OnDiskAtom column = atomSerializer.deserializeFromSSTable(file, sstable.descriptor.version);
+            ByteBuffer columnName = column.name();
+
             if (column instanceof IColumn)
             {
-                if (columnNames.contains(column.name()))
+                if (columnNames.contains(columnName))
                 {
                     result.add(column);
-                    if (++n >= columns.size())
-                        break;
                 }
             }
             else
             {
                 result.add(column);
             }
+
+            // Already consumed all of this block that's going to have columns that apply
to this query.
+            if (comparator.compare(columnName, maximalColumnName) >= 0)
+                break;
         }
     }
 
@@ -231,6 +241,12 @@ public class SSTableNamesIterator extends SimpleAbstractColumnIterator
implement
         {
             long positionToSeek = basePosition + indexInfo.offset;
 
+            // SortedSet.subSet() is end-exclusive, so we special-case that
+            // if it's one of the columns we're looking for
+            ByteBuffer maximalColumnName = columnNames.contains(indexInfo.lastName)
+                                         ? indexInfo.lastName
+                                         : columnNames.subSet(indexInfo.firstName, indexInfo.lastName).last();
+
             // With new promoted indexes, our first seek in the data file will happen at
that point.
             if (file == null)
                 file = createFileDataInput(positionToSeek);
@@ -238,13 +254,20 @@ public class SSTableNamesIterator extends SimpleAbstractColumnIterator
implement
             OnDiskAtom.Serializer atomSerializer = cf.getOnDiskSerializer();
             file.seek(positionToSeek);
             FileMark mark = file.mark();
+
             // TODO only completely deserialize columns we are interested in
             while (file.bytesPastMark(mark) < indexInfo.width)
             {
                 OnDiskAtom column = atomSerializer.deserializeFromSSTable(file, sstable.descriptor.version);
+                ByteBuffer columnName = column.name();
+
                 // we check vs the original Set, not the filtered List, for efficiency
-                if (!(column instanceof IColumn) || columnNames.contains(column.name()))
+                if (!(column instanceof IColumn) || columnNames.contains(columnName))
                     result.add(column);
+
+                // Already consumed all of this block that's going to have columns that apply
to this query.
+                if (comparator.compare(columnName, maximalColumnName) >= 0)
+                    break;
             }
         }
     }


Mime
View raw message