quickstep-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jianq...@apache.org
Subject [2/2] incubator-quickstep git commit: Updates
Date Sat, 15 Oct 2016 23:15:06 GMT
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 <jianqiao@cs.wisc.edu>
Authored: Sat Oct 15 18:14:50 2016 -0500
Committer: Jianqiao Zhu <jianqiao@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();


Mime
View raw message