You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@quickstep.apache.org by ji...@apache.org on 2016/10/15 23:15:05 UTC

[1/2] incubator-quickstep git commit: Initital update

Repository: incubator-quickstep
Updated Branches:
  refs/heads/inline-memcpy [created] 3fcbd5d78


Initital update


Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/07cff2d6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/07cff2d6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/07cff2d6

Branch: refs/heads/inline-memcpy
Commit: 07cff2d640e3a00fe9a12fb9b05836f3a79dc758
Parents: 17ffbb0
Author: Jianqiao Zhu <ji...@cs.wisc.edu>
Authored: Sat Oct 15 15:46:13 2016 -0500
Committer: Jianqiao Zhu <ji...@cs.wisc.edu>
Committed: Sat Oct 15 15:46:13 2016 -0500

----------------------------------------------------------------------
 .../BasicColumnStoreTupleStorageSubBlock.cpp    | 58 +++++++-------
 storage/CMakeLists.txt                          |  3 +
 storage/PackedRowStoreTupleStorageSubBlock.cpp  | 37 +++++----
 storage/SplitRowStoreTupleStorageSubBlock.cpp   | 70 ++++++++---------
 utility/CMakeLists.txt                          |  2 +
 utility/InlineMemcpy.hpp                        | 80 ++++++++++++++++++++
 6 files changed, 167 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/07cff2d6/storage/BasicColumnStoreTupleStorageSubBlock.cpp
----------------------------------------------------------------------
diff --git a/storage/BasicColumnStoreTupleStorageSubBlock.cpp b/storage/BasicColumnStoreTupleStorageSubBlock.cpp
index 34a1620..a62ab02 100644
--- a/storage/BasicColumnStoreTupleStorageSubBlock.cpp
+++ b/storage/BasicColumnStoreTupleStorageSubBlock.cpp
@@ -20,7 +20,6 @@
 #include "storage/BasicColumnStoreTupleStorageSubBlock.hpp"
 
 #include <cstddef>
-#include <cstring>
 #include <unordered_map>
 #include <utility>
 #include <vector>
@@ -49,6 +48,7 @@
 #include "types/operations/comparisons/ComparisonID.hpp"
 #include "types/operations/comparisons/ComparisonUtil.hpp"
 #include "utility/BitVector.hpp"
+#include "utility/InlineMemcpy.hpp"
 #include "utility/Macros.hpp"
 #include "utility/PtrMap.hpp"
 #include "utility/PtrVector.hpp"
@@ -56,7 +56,6 @@
 
 #include "glog/logging.h"
 
-using std::memcpy;
 using std::memmove;
 using std::size_t;
 using std::vector;
@@ -298,16 +297,16 @@ tuple_id BasicColumnStoreTupleStorageSubBlock::bulkInsertTuples(ValueAccessor *a
             if (attr_value == nullptr) {
               column_null_bitmaps_[attr_id].setBit(header_->num_tuples, true);
             } else {
-              memcpy(static_cast<char*>(column_stripes_[attr_id])
-                         + header_->num_tuples * attr_size,
-                     attr_value,
-                     attr_size);
+              InlineMemcpy(static_cast<char*>(column_stripes_[attr_id])
+                               + header_->num_tuples * attr_size,
+                           attr_value,
+                           attr_size);
             }
           } else {
-            memcpy(static_cast<char*>(column_stripes_[attr_id])
-                       + header_->num_tuples * attr_size,
-                   accessor->template getUntypedValue<false>(accessor_attr_id),
-                   attr_size);
+            InlineMemcpy(static_cast<char*>(column_stripes_[attr_id])
+                             + header_->num_tuples * attr_size,
+                         accessor->template getUntypedValue<false>(accessor_attr_id),
+                         attr_size);
           }
           ++accessor_attr_id;
         }
@@ -320,10 +319,10 @@ tuple_id BasicColumnStoreTupleStorageSubBlock::bulkInsertTuples(ValueAccessor *a
              attr_it != relation_.end();
              ++attr_it) {
           const std::size_t attr_size = attr_it->getType().maximumByteLength();
-          memcpy(static_cast<char*>(column_stripes_[attr_it->getID()])
-                     + header_->num_tuples * attr_size,
-                 accessor->template getUntypedValue<false>(accessor_attr_id),
-                 attr_size);
+          InlineMemcpy(static_cast<char*>(column_stripes_[attr_it->getID()])
+                           + header_->num_tuples * attr_size,
+                       accessor->template getUntypedValue<false>(accessor_attr_id),
+                       attr_size);
           ++accessor_attr_id;
         }
         ++(header_->num_tuples);
@@ -361,13 +360,13 @@ tuple_id BasicColumnStoreTupleStorageSubBlock::bulkInsertTuplesWithRemappedAttri
             if (attr_value == nullptr) {
               column_null_bitmaps_[attr_id].setBit(header_->num_tuples, true);
             } else {
-              memcpy(static_cast<char*>(column_stripes_[attr_id])
+              InlineMemcpy(static_cast<char*>(column_stripes_[attr_id])
                          + header_->num_tuples * attr_size,
                      attr_value,
                      attr_size);
             }
           } else {
-            memcpy(static_cast<char*>(column_stripes_[attr_id])
+            InlineMemcpy(static_cast<char*>(column_stripes_[attr_id])
                        + header_->num_tuples * attr_size,
                    accessor->template getUntypedValue<false>(*attribute_map_it),
                    attr_size);
@@ -383,7 +382,7 @@ tuple_id BasicColumnStoreTupleStorageSubBlock::bulkInsertTuplesWithRemappedAttri
              attr_it != relation_.end();
              ++attr_it) {
           const std::size_t attr_size = attr_it->getType().maximumByteLength();
-          memcpy(static_cast<char*>(column_stripes_[attr_it->getID()])
+          InlineMemcpy(static_cast<char*>(column_stripes_[attr_it->getID()])
                      + header_->num_tuples * attr_size,
                  accessor->template getUntypedValue<false>(*attribute_map_it),
                  attr_size);
@@ -793,7 +792,7 @@ bool BasicColumnStoreTupleStorageSubBlock::rebuildInternal() {
 
         // Clear out the tail, which will be reorganized.
         if (ordered_prefix_tuples > 0) {
-          memcpy(null_bitmap_buffers.back().get(), bitmap_location, bitmap_required_bytes);
+          InlineMemcpy(null_bitmap_buffers.back().get(), bitmap_location, bitmap_required_bytes);
           new_null_bitmaps.back().setBitRange(ordered_prefix_tuples,
                                               num_tuples - ordered_prefix_tuples,
                                               false);
@@ -818,11 +817,12 @@ bool BasicColumnStoreTupleStorageSubBlock::rebuildInternal() {
     for (tuple_id unordered_tuple_num = 0;
          unordered_tuple_num < num_tuples - ordered_prefix_tuples;
          ++unordered_tuple_num) {
-      memcpy(static_cast<char*>(column_stripe_buffers[attr_id].get())
-                 + unordered_tuple_num * attr_length,
-             static_cast<char*>(column_stripes_[attr_id]) +
-                 sort_column_values[ordered_prefix_tuples + unordered_tuple_num].getTupleID() * attr_length,
-             attr_length);
+      InlineMemcpy(static_cast<char*>(column_stripe_buffers[attr_id].get())
+                       + unordered_tuple_num * attr_length,
+                   static_cast<char*>(column_stripes_[attr_id]) +
+                       sort_column_values[ordered_prefix_tuples + unordered_tuple_num].getTupleID()
+                           * attr_length,
+                   attr_length);
     }
 
     if (!new_null_bitmaps.elementIsNull(attr_id)) {
@@ -844,14 +844,14 @@ bool BasicColumnStoreTupleStorageSubBlock::rebuildInternal() {
        attr_it != relation_.end();
        ++attr_it) {
     size_t attr_length = attr_it->getType().maximumByteLength();
-    memcpy(static_cast<char*>(column_stripes_[attr_it->getID()]) + ordered_prefix_tuples * attr_length,
-           column_stripe_buffers[attr_it->getID()].get(),
-           (num_tuples - ordered_prefix_tuples) * attr_length);
+    InlineMemcpy(static_cast<char*>(column_stripes_[attr_it->getID()]) + ordered_prefix_tuples * attr_length,
+                 column_stripe_buffers[attr_it->getID()].get(),
+                 (num_tuples - ordered_prefix_tuples) * attr_length);
 
     if (!null_bitmap_buffers.elementIsNull(attr_it->getID())) {
-      std::memcpy(bitmap_location,
-                  null_bitmap_buffers[attr_it->getID()].get(),
-                  bitmap_required_bytes);
+      InlineMemcpy(bitmap_location,
+                   null_bitmap_buffers[attr_it->getID()].get(),
+                   bitmap_required_bytes);
       bitmap_location += bitmap_required_bytes;
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/07cff2d6/storage/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/storage/CMakeLists.txt b/storage/CMakeLists.txt
index f05cc46..798c04b 100644
--- a/storage/CMakeLists.txt
+++ b/storage/CMakeLists.txt
@@ -329,6 +329,7 @@ target_link_libraries(quickstep_storage_BasicColumnStoreTupleStorageSubBlock
                       quickstep_types_operations_comparisons_ComparisonID
                       quickstep_types_operations_comparisons_ComparisonUtil
                       quickstep_utility_BitVector
+                      quickstep_utility_InlineMemcpy
                       quickstep_utility_Macros
                       quickstep_utility_PtrMap
                       quickstep_utility_PtrVector
@@ -840,6 +841,7 @@ target_link_libraries(quickstep_storage_PackedRowStoreTupleStorageSubBlock
                       quickstep_types_TypedValue
                       quickstep_types_containers_Tuple
                       quickstep_utility_BitVector
+                      quickstep_utility_InlineMemcpy
                       quickstep_utility_Macros)
 target_link_libraries(quickstep_storage_PackedRowStoreValueAccessor
                       quickstep_catalog_CatalogRelationSchema
@@ -937,6 +939,7 @@ target_link_libraries(quickstep_storage_SplitRowStoreTupleStorageSubBlock
                       quickstep_storage_ValueAccessorUtil
                       quickstep_types_TypedValue
                       quickstep_utility_BitVector
+                      quickstep_utility_InlineMemcpy
                       quickstep_utility_Macros
                       quickstep_utility_ScopedBuffer)
 target_link_libraries(quickstep_storage_SplitRowStoreValueAccessor

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/07cff2d6/storage/PackedRowStoreTupleStorageSubBlock.cpp
----------------------------------------------------------------------
diff --git a/storage/PackedRowStoreTupleStorageSubBlock.cpp b/storage/PackedRowStoreTupleStorageSubBlock.cpp
index 0ad4a4c..4ef3f4f 100644
--- a/storage/PackedRowStoreTupleStorageSubBlock.cpp
+++ b/storage/PackedRowStoreTupleStorageSubBlock.cpp
@@ -20,7 +20,6 @@
 #include "storage/PackedRowStoreTupleStorageSubBlock.hpp"
 
 #include <cstddef>
-#include <cstring>
 #include <vector>
 
 #include "catalog/CatalogAttribute.hpp"
@@ -38,10 +37,10 @@
 #include "types/TypedValue.hpp"
 #include "types/containers/Tuple.hpp"
 #include "utility/BitVector.hpp"
+#include "utility/InlineMemcpy.hpp"
 #include "utility/Macros.hpp"
 
 using std::vector;
-using std::memcpy;
 using std::size_t;
 
 namespace quickstep {
@@ -164,12 +163,12 @@ tuple_id PackedRowStoreTupleStorageSubBlock::bulkInsertTuples(ValueAccessor *acc
                   header_->num_tuples * num_nullable_attrs + nullable_idx,
                   true);
             } else {
-              memcpy(dest_addr, attr_value, attr_size);
+              InlineMemcpy(dest_addr, attr_value, attr_size);
             }
           } else {
-            memcpy(dest_addr,
-                   accessor->template getUntypedValue<false>(curr_attr),
-                   attr_size);
+            InlineMemcpy(dest_addr,
+                         accessor->template getUntypedValue<false>(curr_attr),
+                         attr_size);
           }
           dest_addr += attr_size;
         }
@@ -184,15 +183,15 @@ tuple_id PackedRowStoreTupleStorageSubBlock::bulkInsertTuples(ValueAccessor *acc
       const std::size_t attrs_total_size = relation_.getMaximumByteLength();
       while (this->hasSpaceToInsert<false>(1) && accessor->next()) {
         if (fast_copy) {
-          memcpy(dest_addr,
-                 accessor->template getUntypedValue<false>(0),
-                 attrs_total_size);
+          InlineMemcpy(dest_addr,
+                       accessor->template getUntypedValue<false>(0),
+                       attrs_total_size);
         } else {
           for (std::size_t curr_attr = 0; curr_attr < num_attrs; ++curr_attr) {
             const std::size_t attr_size = attrs_max_size[curr_attr];
-            memcpy(dest_addr,
-                   accessor->template getUntypedValue<false>(curr_attr),
-                   attr_size);
+            InlineMemcpy(dest_addr,
+                         accessor->template getUntypedValue<false>(curr_attr),
+                         attr_size);
             dest_addr += attr_size;
           }
         }
@@ -235,12 +234,12 @@ tuple_id PackedRowStoreTupleStorageSubBlock::bulkInsertTuplesWithRemappedAttribu
                   header_->num_tuples * num_nullable_attrs + nullable_idx,
                   true);
             } else {
-              memcpy(dest_addr, attr_value, attr_size);
+              InlineMemcpy(dest_addr, attr_value, attr_size);
             }
           } else {
-            memcpy(dest_addr,
-                   accessor->template getUntypedValue<false>(attribute_map[curr_attr]),
-                   attr_size);
+            InlineMemcpy(dest_addr,
+                         accessor->template getUntypedValue<false>(attribute_map[curr_attr]),
+                         attr_size);
           }
           dest_addr += attr_size;
         }
@@ -250,9 +249,9 @@ tuple_id PackedRowStoreTupleStorageSubBlock::bulkInsertTuplesWithRemappedAttribu
       while (this->hasSpaceToInsert<false>(1) && accessor->next()) {
         for (std::size_t curr_attr = 0; curr_attr < num_attrs; ++curr_attr) {
           const std::size_t attr_size = attrs_max_size[curr_attr];
-          memcpy(dest_addr,
-                 accessor->template getUntypedValue<false>(attribute_map[curr_attr]),
-                 attr_size);
+          InlineMemcpy(dest_addr,
+                       accessor->template getUntypedValue<false>(attribute_map[curr_attr]),
+                       attr_size);
           dest_addr += attr_size;
         }
         ++(header_->num_tuples);

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/07cff2d6/storage/SplitRowStoreTupleStorageSubBlock.cpp
----------------------------------------------------------------------
diff --git a/storage/SplitRowStoreTupleStorageSubBlock.cpp b/storage/SplitRowStoreTupleStorageSubBlock.cpp
index f955c99..3a14a09 100644
--- a/storage/SplitRowStoreTupleStorageSubBlock.cpp
+++ b/storage/SplitRowStoreTupleStorageSubBlock.cpp
@@ -21,7 +21,6 @@
 
 #include <cstddef>
 #include <cstdint>
-#include <cstring>
 #include <utility>
 #include <vector>
 
@@ -34,6 +33,7 @@
 #include "storage/ValueAccessorUtil.hpp"
 #include "types/TypedValue.hpp"
 #include "utility/BitVector.hpp"
+#include "utility/InlineMemcpy.hpp"
 #include "utility/Macros.hpp"
 #include "utility/ScopedBuffer.hpp"
 
@@ -287,17 +287,17 @@ tuple_id SplitRowStoreTupleStorageSubBlock::bulkInsertTuples(ValueAccessor *acce
               if (attr_value == nullptr) {
                 tuple_null_bitmap.setBit(nullable_idx, true);
               } else {
-                std::memcpy(fixed_length_attr_storage
-                                + relation_.getFixedLengthAttributeOffset(attr_it->getID()),
-                            attr_value,
-                            attr_it->getType().maximumByteLength());
+                InlineMemcpy(fixed_length_attr_storage
+                                 + relation_.getFixedLengthAttributeOffset(attr_it->getID()),
+                             attr_value,
+                             attr_it->getType().maximumByteLength());
               }
             } else {
               const void *attr_value = accessor->template getUntypedValue<false>(accessor_attr_id);
-              std::memcpy(fixed_length_attr_storage
-                              + relation_.getFixedLengthAttributeOffset(attr_it->getID()),
-                          attr_value,
-                          attr_it->getType().maximumByteLength());
+              InlineMemcpy(fixed_length_attr_storage
+                               + relation_.getFixedLengthAttributeOffset(attr_it->getID()),
+                           attr_value,
+                           attr_it->getType().maximumByteLength());
             }
           }
           occupancy_bitmap_->setBit(pos, true);
@@ -368,10 +368,10 @@ tuple_id SplitRowStoreTupleStorageSubBlock::bulkInsertTuples(ValueAccessor *acce
                attr_it != relation_.end();
                ++attr_it, ++accessor_attr_id) {
             const void *attr_value = accessor->template getUntypedValue<false>(accessor_attr_id);
-            std::memcpy(fixed_length_attr_storage
-                            + relation_.getFixedLengthAttributeOffset(attr_it->getID()),
-                        attr_value,
-                        attr_it->getType().maximumByteLength());
+            InlineMemcpy(fixed_length_attr_storage
+                             + relation_.getFixedLengthAttributeOffset(attr_it->getID()),
+                         attr_value,
+                         attr_it->getType().maximumByteLength());
           }
           occupancy_bitmap_->setBit(pos, true);
           ++(header_->num_tuples);
@@ -472,17 +472,17 @@ tuple_id SplitRowStoreTupleStorageSubBlock::bulkInsertTuplesWithRemappedAttribut
               if (attr_value == nullptr) {
                 tuple_null_bitmap.setBit(nullable_idx, true);
               } else {
-                std::memcpy(fixed_length_attr_storage
-                                + relation_.getFixedLengthAttributeOffset(attr_it->getID()),
-                            attr_value,
-                            attr_it->getType().maximumByteLength());
+                InlineMemcpy(fixed_length_attr_storage
+                                 + relation_.getFixedLengthAttributeOffset(attr_it->getID()),
+                             attr_value,
+                             attr_it->getType().maximumByteLength());
               }
             } else {
               const void *attr_value = accessor->template getUntypedValue<false>(*attr_map_it);
-              std::memcpy(fixed_length_attr_storage
-                              + relation_.getFixedLengthAttributeOffset(attr_it->getID()),
-                          attr_value,
-                          attr_it->getType().maximumByteLength());
+              InlineMemcpy(fixed_length_attr_storage
+                               + relation_.getFixedLengthAttributeOffset(attr_it->getID()),
+                           attr_value,
+                           attr_it->getType().maximumByteLength());
             }
           }
           occupancy_bitmap_->setBit(pos, true);
@@ -552,10 +552,10 @@ tuple_id SplitRowStoreTupleStorageSubBlock::bulkInsertTuplesWithRemappedAttribut
                attr_it != relation_.end();
                ++attr_it, ++attr_map_it) {
             const void *attr_value = accessor->template getUntypedValue<false>(*attr_map_it);
-            std::memcpy(fixed_length_attr_storage
-                            + relation_.getFixedLengthAttributeOffset(attr_it->getID()),
-                        attr_value,
-                        attr_it->getType().maximumByteLength());
+            InlineMemcpy(fixed_length_attr_storage
+                             + relation_.getFixedLengthAttributeOffset(attr_it->getID()),
+                         attr_value,
+                         attr_it->getType().maximumByteLength());
           }
           occupancy_bitmap_->setBit(pos, true);
           ++(header_->num_tuples);
@@ -835,9 +835,9 @@ void SplitRowStoreTupleStorageSubBlock::rebuild() {
     std::size_t dest = occupancy_bitmap_->firstZero();
     std::size_t src = occupancy_bitmap_->lastOne(header_->max_tid + 1);
     while (dest < static_cast<std::size_t>(header_->num_tuples)) {
-      std::memcpy(static_cast<char*>(tuple_storage_) + dest * tuple_slot_bytes_,
-                  static_cast<char*>(tuple_storage_) + src * tuple_slot_bytes_,
-                  tuple_slot_bytes_);
+      InlineMemcpy(static_cast<char*>(tuple_storage_) + dest * tuple_slot_bytes_,
+                   static_cast<char*>(tuple_storage_) + src * tuple_slot_bytes_,
+                   tuple_slot_bytes_);
       dest = occupancy_bitmap_->firstZero(dest + 1);
       src = occupancy_bitmap_->lastOne(src);
     }
@@ -873,10 +873,10 @@ void SplitRowStoreTupleStorageSubBlock::rebuild() {
         const int variable_idx = relation_.getVariableLengthAttributeIndex(attr_it->getID());
         if (variable_idx != -1) {
           // Copy into the temporary buffer.
-          std::memcpy(static_cast<char*>(packed_buffer.get()) + buffer_pos,
-                      static_cast<char*>(tuple_storage_)
-                          + variable_length_info_array[variable_idx << 1],
-                      variable_length_info_array[(variable_idx << 1) + 1]);
+          InlineMemcpy(static_cast<char*>(packed_buffer.get()) + buffer_pos,
+                       static_cast<char*>(tuple_storage_)
+                           + variable_length_info_array[variable_idx << 1],
+                       variable_length_info_array[(variable_idx << 1) + 1]);
           // Temporarily reset the offset entry in the slot to the offset in
           // the temp buffer (will be corrected in a second pass below).
           variable_length_info_array[variable_idx << 1] = buffer_pos;
@@ -888,9 +888,9 @@ void SplitRowStoreTupleStorageSubBlock::rebuild() {
     if (buffer_pos != 0) {
       // Copy temporary packing buffer back into block.
       const std::uint32_t variable_start = tuple_storage_bytes_ - buffer_pos;
-      std::memcpy(static_cast<char*>(tuple_storage_) + variable_start,
-                  packed_buffer.get(),
-                  buffer_pos);
+      InlineMemcpy(static_cast<char*>(tuple_storage_) + variable_start,
+                   packed_buffer.get(),
+                   buffer_pos);
       // Correct offsets of variable-length attribute storage to point to the
       // actual location in the block.
       for (tuple_id tid = 0; tid < header_->num_tuples; ++tid) {

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/07cff2d6/utility/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/utility/CMakeLists.txt b/utility/CMakeLists.txt
index ddaae45..8765a57 100644
--- a/utility/CMakeLists.txt
+++ b/utility/CMakeLists.txt
@@ -174,6 +174,7 @@ add_library(quickstep_utility_ExecutionDAGVisualizer
             ExecutionDAGVisualizer.hpp)
 add_library(quickstep_utility_Glob Glob.cpp Glob.hpp)
 add_library(quickstep_utility_HashPair ../empty_src.cpp HashPair.hpp)
+add_library(quickstep_utility_InlineMemcpy ../empty_src.cpp InlineMemcpy.hpp)
 add_library(quickstep_utility_Macros ../empty_src.cpp Macros.hpp)
 add_library(quickstep_utility_MemStream ../empty_src.cpp MemStream.hpp)
 add_library(quickstep_utility_PlanVisualizer PlanVisualizer.cpp PlanVisualizer.hpp)
@@ -323,6 +324,7 @@ target_link_libraries(quickstep_utility
                       quickstep_utility_ExecutionDAGVisualizer
                       quickstep_utility_Glob
                       quickstep_utility_HashPair
+                      quickstep_utility_InlineMemcpy
                       quickstep_utility_Macros
                       quickstep_utility_MemStream
                       quickstep_utility_PlanVisualizer

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/07cff2d6/utility/InlineMemcpy.hpp
----------------------------------------------------------------------
diff --git a/utility/InlineMemcpy.hpp b/utility/InlineMemcpy.hpp
new file mode 100644
index 0000000..ff7ae83
--- /dev/null
+++ b/utility/InlineMemcpy.hpp
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ **/
+
+#ifndef QUICKSTEP_UTILITY_INLINE_MEMCPY_HPP_
+#define QUICKSTEP_UTILITY_INLINE_MEMCPY_HPP_
+
+#include <cstring>
+
+namespace quickstep {
+
+/** \addtogroup Utility
+ *  @{
+ */
+
+inline void InlineMemcpy(void *dst, const void *src, const std::size_t size) {
+#define INLINE_ENTRY_(len) \
+  case len: std::memcpy(dst, src, len); break
+
+  switch (size) {
+    INLINE_ENTRY_(1);
+    INLINE_ENTRY_(2);
+    INLINE_ENTRY_(3);
+    INLINE_ENTRY_(4);
+    INLINE_ENTRY_(5);
+    INLINE_ENTRY_(6);
+    INLINE_ENTRY_(7);
+    INLINE_ENTRY_(8);
+    INLINE_ENTRY_(9);
+    INLINE_ENTRY_(10);
+    INLINE_ENTRY_(11);
+    INLINE_ENTRY_(12);
+    INLINE_ENTRY_(13);
+    INLINE_ENTRY_(14);
+    INLINE_ENTRY_(15);
+    INLINE_ENTRY_(16);
+    INLINE_ENTRY_(17);
+    INLINE_ENTRY_(18);
+    INLINE_ENTRY_(19);
+    INLINE_ENTRY_(20);
+    INLINE_ENTRY_(21);
+    INLINE_ENTRY_(22);
+    INLINE_ENTRY_(23);
+    INLINE_ENTRY_(24);
+    INLINE_ENTRY_(25);
+    INLINE_ENTRY_(26);
+    INLINE_ENTRY_(27);
+    INLINE_ENTRY_(28);
+    INLINE_ENTRY_(29);
+    INLINE_ENTRY_(30);
+    INLINE_ENTRY_(31);
+    INLINE_ENTRY_(32);
+
+    default:
+      std::memcpy(dst, src, size);
+  }
+
+#undef INLINE_ENTRY_
+}
+
+/** @} */
+
+}  // namespace quickstep
+
+#endif  // QUICKSTEP_UTILITY_INLINE_MEMCPY_HPP_


[2/2] incubator-quickstep git commit: Updates

Posted by ji...@apache.org.
Updates


Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/3fcbd5d7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/3fcbd5d7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/3fcbd5d7

Branch: refs/heads/inline-memcpy
Commit: 3fcbd5d787ae483dd547294d52151151945bcc57
Parents: 07cff2d
Author: Jianqiao Zhu <ji...@cs.wisc.edu>
Authored: Sat Oct 15 18:14:50 2016 -0500
Committer: Jianqiao Zhu <ji...@cs.wisc.edu>
Committed: Sat Oct 15 18:14:50 2016 -0500

----------------------------------------------------------------------
 .../BasicColumnStoreTupleStorageSubBlock.cpp    | 88 +++++++++++++++-----
 .../BasicColumnStoreTupleStorageSubBlock.hpp    |  4 +
 storage/PackedRowStoreTupleStorageSubBlock.cpp  | 75 ++++++++++++++---
 storage/PackedRowStoreTupleStorageSubBlock.hpp  |  2 +
 storage/StorageBlockLayout.cpp                  |  1 +
 5 files changed, 134 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/3fcbd5d7/storage/BasicColumnStoreTupleStorageSubBlock.cpp
----------------------------------------------------------------------
diff --git a/storage/BasicColumnStoreTupleStorageSubBlock.cpp b/storage/BasicColumnStoreTupleStorageSubBlock.cpp
index a62ab02..f4ef126 100644
--- a/storage/BasicColumnStoreTupleStorageSubBlock.cpp
+++ b/storage/BasicColumnStoreTupleStorageSubBlock.cpp
@@ -313,19 +313,39 @@ tuple_id BasicColumnStoreTupleStorageSubBlock::bulkInsertTuples(ValueAccessor *a
         ++(header_->num_tuples);
       }
     } else {
-      while (this->hasSpaceToInsert(1) && accessor->next()) {
-        attribute_id accessor_attr_id = 0;
-        for (CatalogRelationSchema::const_iterator attr_it = relation_.begin();
-             attr_it != relation_.end();
-             ++attr_it) {
-          const std::size_t attr_size = attr_it->getType().maximumByteLength();
-          InlineMemcpy(static_cast<char*>(column_stripes_[attr_it->getID()])
-                           + header_->num_tuples * attr_size,
-                       accessor->template getUntypedValue<false>(accessor_attr_id),
+      const std::size_t max_tuples = this->getNumAvailableTuplesForInsertion();
+      const std::size_t num_attrs = relation_.size();
+      const std::vector<std::size_t> &attrs_max_size =
+          relation_.getMaximumAttributeByteLengths();
+
+      if (num_attrs == 1) {
+        const std::size_t attr_size = attrs_max_size.front();
+        char *dest_addr = static_cast<char*>(column_stripes_.front())
+                              + header_->num_tuples * attr_size;
+        for (std::size_t i = 0; i < max_tuples && accessor->next(); ++i) {
+          InlineMemcpy(dest_addr,
+                       accessor->template getUntypedValue<false>(0),
                        attr_size);
-          ++accessor_attr_id;
+          dest_addr += attr_size;
+          ++(header_->num_tuples);
         }
-        ++(header_->num_tuples);
+      } else {
+        std::vector<tuple_id> tuples;
+        for (std::size_t i = 0; i < max_tuples && accessor->next(); ++i) {
+          tuples.emplace_back(accessor->getCurrentPosition());
+        }
+        for (attribute_id attr_id = 0; attr_id < num_attrs; ++attr_id) {
+          const std::size_t attr_size = attrs_max_size[attr_id];
+          char *dest_addr = static_cast<char*>(column_stripes_[attr_id])
+                                + header_->num_tuples * attr_size;
+          for (const tuple_id tid : tuples) {
+            InlineMemcpy(dest_addr,
+                         accessor->template getUntypedValueAtAbsolutePosition<false>(attr_id, tid),
+                         attr_size);
+            dest_addr += attr_size;
+          }
+        }
+        header_->num_tuples += tuples.size();
       }
     }
   });
@@ -376,19 +396,41 @@ tuple_id BasicColumnStoreTupleStorageSubBlock::bulkInsertTuplesWithRemappedAttri
         ++(header_->num_tuples);
       }
     } else {
-      while (this->hasSpaceToInsert(1) && accessor->next()) {
-        std::vector<attribute_id>::const_iterator attribute_map_it = attribute_map.begin();
-        for (CatalogRelationSchema::const_iterator attr_it = relation_.begin();
-             attr_it != relation_.end();
-             ++attr_it) {
-          const std::size_t attr_size = attr_it->getType().maximumByteLength();
-          InlineMemcpy(static_cast<char*>(column_stripes_[attr_it->getID()])
-                     + header_->num_tuples * attr_size,
-                 accessor->template getUntypedValue<false>(*attribute_map_it),
-                 attr_size);
-          ++attribute_map_it;
+      const std::size_t max_tuples = this->getNumAvailableTuplesForInsertion();
+      const std::size_t num_attrs = relation_.size();
+      const std::vector<std::size_t> &attrs_max_size =
+          relation_.getMaximumAttributeByteLengths();
+
+      if (num_attrs == 1) {
+        const attribute_id attr_id = attribute_map.front();
+        const std::size_t attr_size = attrs_max_size.front();
+        char *dest_addr = static_cast<char*>(column_stripes_.front())
+                              + header_->num_tuples * attr_size;
+        for (std::size_t i = 0; i < max_tuples && accessor->next(); ++i) {
+          InlineMemcpy(dest_addr,
+                       accessor->template getUntypedValue<false>(attr_id),
+                       attr_size);
+          dest_addr += attr_size;
+          ++(header_->num_tuples);
         }
-        ++(header_->num_tuples);
+      } else {
+        std::vector<tuple_id> tuples;
+        for (std::size_t i = 0; i < max_tuples && accessor->next(); ++i) {
+          tuples.emplace_back(accessor->getCurrentPosition());
+        }
+        for (attribute_id i = 0; i < num_attrs; ++i) {
+          const attribute_id attr_id = attribute_map[i];
+          const std::size_t attr_size = attrs_max_size[i];
+          char *dest_addr = static_cast<char*>(column_stripes_[i])
+                                + header_->num_tuples * attr_size;
+          for (const tuple_id tid : tuples) {
+            InlineMemcpy(dest_addr,
+                         accessor->template getUntypedValueAtAbsolutePosition<false>(attr_id, tid),
+                         attr_size);
+            dest_addr += attr_size;
+          }
+        }
+        header_->num_tuples += tuples.size();
       }
     }
   });

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/3fcbd5d7/storage/BasicColumnStoreTupleStorageSubBlock.hpp
----------------------------------------------------------------------
diff --git a/storage/BasicColumnStoreTupleStorageSubBlock.hpp b/storage/BasicColumnStoreTupleStorageSubBlock.hpp
index e896a7a..8329657 100644
--- a/storage/BasicColumnStoreTupleStorageSubBlock.hpp
+++ b/storage/BasicColumnStoreTupleStorageSubBlock.hpp
@@ -194,6 +194,10 @@ class BasicColumnStoreTupleStorageSubBlock : public TupleStorageSubBlock {
     return (num_tuples <= max_tuples_ - header_->num_tuples);
   }
 
+  inline tuple_id getNumAvailableTuplesForInsertion() const {
+    return max_tuples_ - header_->num_tuples;
+  }
+
   // Copy attribute values from 'tuple' into the appropriate column stripes
   // at the offset specified by 'position'. If 'position' is not at the current
   // end of tuples in this block, subsequent tuples are shifted back to make

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/3fcbd5d7/storage/PackedRowStoreTupleStorageSubBlock.cpp
----------------------------------------------------------------------
diff --git a/storage/PackedRowStoreTupleStorageSubBlock.cpp b/storage/PackedRowStoreTupleStorageSubBlock.cpp
index 4ef3f4f..934ca71 100644
--- a/storage/PackedRowStoreTupleStorageSubBlock.cpp
+++ b/storage/PackedRowStoreTupleStorageSubBlock.cpp
@@ -175,27 +175,49 @@ tuple_id PackedRowStoreTupleStorageSubBlock::bulkInsertTuples(ValueAccessor *acc
         ++(header_->num_tuples);
       }
     } else {
+      const std::size_t attrs_total_size = relation_.getMaximumByteLength();
+
       // If the accessor is from a packed row store, we can optimize the
       // memcpy by avoiding iterating over each attribute.
       const bool fast_copy =
           (accessor->getImplementationType() ==
               ValueAccessor::Implementation::kCompressedPackedRowStore);
-      const std::size_t attrs_total_size = relation_.getMaximumByteLength();
-      while (this->hasSpaceToInsert<false>(1) && accessor->next()) {
-        if (fast_copy) {
+      if (fast_copy) {
+        while (this->hasSpaceToInsert<false>(1) && accessor->next()) {
           InlineMemcpy(dest_addr,
                        accessor->template getUntypedValue<false>(0),
                        attrs_total_size);
-        } else {
-          for (std::size_t curr_attr = 0; curr_attr < num_attrs; ++curr_attr) {
-            const std::size_t attr_size = attrs_max_size[curr_attr];
+          ++(header_->num_tuples);
+        }
+      } else {
+        const std::size_t max_tuples = this->getNumAvailableTuplesForInsertion();
+        if (num_attrs == 1) {
+          const std::size_t attr_size = attrs_max_size.front();
+          for (std::size_t i = 0; i < max_tuples && accessor->next(); ++i) {
             InlineMemcpy(dest_addr,
-                         accessor->template getUntypedValue<false>(curr_attr),
+                         accessor->template getUntypedValue<false>(0),
                          attr_size);
             dest_addr += attr_size;
+            ++(header_->num_tuples);
+          }
+        } else {
+          std::vector<tuple_id> tuples;
+          for (std::size_t i = 0; i < max_tuples && accessor->next(); ++i) {
+            tuples.emplace_back(accessor->getCurrentPosition());
+          }
+          for (attribute_id attr_id = 0; attr_id < num_attrs; ++attr_id) {
+            const std::size_t attr_size = attrs_max_size[attr_id];
+            char *attr_dest_addr = dest_addr;
+            for (const tuple_id tid : tuples) {
+              InlineMemcpy(attr_dest_addr,
+                           accessor->template getUntypedValueAtAbsolutePosition<false>(attr_id, tid),
+                           attr_size);
+              attr_dest_addr += attrs_total_size;
+            }
+            dest_addr += attr_size;
           }
+          header_->num_tuples += tuples.size();
         }
-        ++(header_->num_tuples);
       }
     }
   });
@@ -246,15 +268,36 @@ tuple_id PackedRowStoreTupleStorageSubBlock::bulkInsertTuplesWithRemappedAttribu
         ++(header_->num_tuples);
       }
     } else {
-      while (this->hasSpaceToInsert<false>(1) && accessor->next()) {
-        for (std::size_t curr_attr = 0; curr_attr < num_attrs; ++curr_attr) {
-          const std::size_t attr_size = attrs_max_size[curr_attr];
+      const std::size_t max_tuples = this->getNumAvailableTuplesForInsertion();
+      if (num_attrs == 1) {
+        const attribute_id attr_id = attribute_map.front();
+        const std::size_t attr_size = attrs_max_size.front();
+        for (std::size_t i = 0; i < max_tuples && accessor->next(); ++i) {
           InlineMemcpy(dest_addr,
-                       accessor->template getUntypedValue<false>(attribute_map[curr_attr]),
+                       accessor->template getUntypedValue<false>(attr_id),
                        attr_size);
           dest_addr += attr_size;
+          ++(header_->num_tuples);
         }
-        ++(header_->num_tuples);
+      } else {
+        std::vector<tuple_id> tuples;
+        for (std::size_t i = 0; i < max_tuples && accessor->next(); ++i) {
+          tuples.emplace_back(accessor->getCurrentPosition());
+        }
+        const std::size_t attrs_total_size = relation_.getFixedByteLength();
+        for (std::size_t i = 0; i < num_attrs; ++i) {
+          const attribute_id attr_id = attribute_map[i];
+          const std::size_t attr_size = attrs_max_size[i];
+          char *attr_dest_addr = dest_addr;
+          for (const tuple_id tid : tuples) {
+            InlineMemcpy(attr_dest_addr,
+                         accessor->template getUntypedValueAtAbsolutePosition<false>(attr_id, tid),
+                         attr_size);
+            attr_dest_addr += attrs_total_size;
+          }
+          dest_addr += attr_size;
+        }
+        header_->num_tuples += tuples.size();
       }
     }
   });
@@ -440,6 +483,12 @@ bool PackedRowStoreTupleStorageSubBlock::hasSpaceToInsert(const tuple_id num_tup
   }
 }
 
+tuple_id PackedRowStoreTupleStorageSubBlock::getNumAvailableTuplesForInsertion() const {
+  const std::size_t total_tuple_memory_size =
+      sub_block_memory_size_ - (sizeof(PackedRowStoreHeader) + null_bitmap_bytes_);
+  return total_tuple_memory_size / relation_.getFixedByteLength() - header_->num_tuples;
+}
+
 // Make sure both versions get compiled in.
 template bool PackedRowStoreTupleStorageSubBlock::hasSpaceToInsert<false>(
     const tuple_id num_tuples) const;

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/3fcbd5d7/storage/PackedRowStoreTupleStorageSubBlock.hpp
----------------------------------------------------------------------
diff --git a/storage/PackedRowStoreTupleStorageSubBlock.hpp b/storage/PackedRowStoreTupleStorageSubBlock.hpp
index 0cd41f4..560fcc8 100644
--- a/storage/PackedRowStoreTupleStorageSubBlock.hpp
+++ b/storage/PackedRowStoreTupleStorageSubBlock.hpp
@@ -201,6 +201,8 @@ class PackedRowStoreTupleStorageSubBlock: public TupleStorageSubBlock {
   template <bool nullable_attrs>
   bool hasSpaceToInsert(const tuple_id num_tuples) const;
 
+  inline tuple_id getNumAvailableTuplesForInsertion() const;
+
   PackedRowStoreHeader *header_;
   std::unique_ptr<BitVector<false>> null_bitmap_;
   std::size_t null_bitmap_bytes_;

http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/3fcbd5d7/storage/StorageBlockLayout.cpp
----------------------------------------------------------------------
diff --git a/storage/StorageBlockLayout.cpp b/storage/StorageBlockLayout.cpp
index bdeb9cb..6df893a 100644
--- a/storage/StorageBlockLayout.cpp
+++ b/storage/StorageBlockLayout.cpp
@@ -158,6 +158,7 @@ StorageBlockLayout* StorageBlockLayout::GenerateDefaultLayout(const CatalogRelat
     tuple_store_description->set_sub_block_type(TupleStorageSubBlockDescription::SPLIT_ROW_STORE);
   } else {
     tuple_store_description->set_sub_block_type(TupleStorageSubBlockDescription::PACKED_ROW_STORE);
+//    tuple_store_description->set_sub_block_type(TupleStorageSubBlockDescription::BASIC_COLUMN_STORE);
   }
 
   layout->finalize();