You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by wd...@apache.org on 2018/05/09 03:20:56 UTC
kudu git commit: Fast path scanning blocks of deleted rows
Repository: kudu
Updated Branches:
refs/heads/branch-1.6.x 807648e34 -> f0d95c27e
Fast path scanning blocks of deleted rows
This adds some very simple fast-paths in the case that an entire row
block consists of rows that were deleted.
The first is in the block materialization code: if delta application
results in all rows being deleted, we don't need to move forward and
materialize any columns.
The second is before serializing scan responses to the client. In this
case we don't need to loop over each column and read the selection
vector for each column. Instead we can just return immediately.
I tested this on a table where I'd inserted a few billion rows, deleted
them all, and then re-inserted them. Before the patch, a simple 'SELECT
* FROM t LIMIT 10' took 306sec. With the first optimization only, it
took about 10 seconds. With the second one as well, it took about 2.2
seconds.
There are probably more general optimizations that could be done for
sparsely-populated RowBlocks (eg where just a few rows are selected) but
they are much more complex, and it's relatively common for users to
delete large consecutive runs of rows. For example, users may use
'DELETE' all rows in a table or partition before re-adding them, or they
may delete all data corresponding to some prefix of the PK.
Change-Id: I9fa891c0f4e857ddd1f873ad4855154d078be6b8
Reviewed-on: http://gerrit.cloudera.org:8080/10213
Tested-by: Todd Lipcon <to...@apache.org>
Reviewed-by: Will Berkeley <wd...@gmail.com>
Reviewed-on: http://gerrit.cloudera.org:8080/10329
Tested-by: Kudu Jenkins
Reviewed-by: Andrew Wong <aw...@cloudera.com>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/f0d95c27
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/f0d95c27
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/f0d95c27
Branch: refs/heads/branch-1.6.x
Commit: f0d95c27ef5f42971c3c8367e1538d1303f23c3e
Parents: 807648e
Author: Todd Lipcon <to...@apache.org>
Authored: Wed Apr 25 15:54:45 2018 -0700
Committer: Will Berkeley <wd...@gmail.com>
Committed: Wed May 9 03:19:13 2018 +0000
----------------------------------------------------------------------
src/kudu/common/generic_iterators.cc | 7 +++++++
src/kudu/tserver/tablet_service.cc | 8 ++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/f0d95c27/src/kudu/common/generic_iterators.cc
----------------------------------------------------------------------
diff --git a/src/kudu/common/generic_iterators.cc b/src/kudu/common/generic_iterators.cc
index 66b5d8a..811682c 100644
--- a/src/kudu/common/generic_iterators.cc
+++ b/src/kudu/common/generic_iterators.cc
@@ -524,6 +524,13 @@ Status MaterializingIterator::MaterializeBlock(RowBlock *dst) {
// been deleted.
RETURN_NOT_OK(iter_->InitializeSelectionVector(dst->selection_vector()));
+ // It's relatively common to delete large sequential chunks of rows.
+ // We can fast-path that case and avoid reading any column data.
+ if (!dst->selection_vector()->AnySelected()) {
+ DVLOG(1) << "Fast path over " << dst->nrows() << " deleted rows";
+ return Status::OK();
+ }
+
for (const auto& col_pred : col_idx_predicates_) {
// Materialize the column itself into the row block.
ColumnBlock dst_col(dst->column_block(get<0>(col_pred)));
http://git-wip-us.apache.org/repos/asf/kudu/blob/f0d95c27/src/kudu/tserver/tablet_service.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/tablet_service.cc b/src/kudu/tserver/tablet_service.cc
index 9d47465..34836c6 100644
--- a/src/kudu/tserver/tablet_service.cc
+++ b/src/kudu/tserver/tablet_service.cc
@@ -479,8 +479,12 @@ class ScanResultCopier : public ScanResultCollector {
pad_unixtime_micros_to_16_bytes_(false) {}
void HandleRowBlock(const Schema* client_projection_schema,
- const RowBlock& row_block) override {
- num_rows_returned_ += row_block.selection_vector()->CountSelected();
+ const RowBlock& row_block) override {
+ int64_t num_selected = row_block.selection_vector()->CountSelected();
+ // Fast-path empty blocks (eg because the predicate didn't match any rows or
+ // all rows in the block were deleted)
+ if (num_selected == 0) return;
+ num_rows_returned_ += num_selected;
SerializeRowBlock(row_block, rowblock_pb_, client_projection_schema,
rows_data_, indirect_data_, pad_unixtime_micros_to_16_bytes_);
SetLastRow(row_block, &last_primary_key_);