Skip to content
1 change: 1 addition & 0 deletions benchmarks/duckdb_comparison_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct CloudSQLContext {
txn_manager = std::make_unique<transaction::TransactionManager>(*lock_manager, *catalog, *bpm);
executor = std::make_unique<QueryExecutor>(*catalog, *bpm, *lock_manager, *txn_manager);
executor->set_local_only(true);
executor->set_storage_manager(storage.get()); // Enable use_vectorized for large scans

// Create lineitem table (TPC-H schema, simplified)
CreateTableStatement create_stmt;
Expand Down
23 changes: 23 additions & 0 deletions include/executor/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ class ColumnVector {
size_ = 0;
null_bitmap_.clear();
}

/**
* @brief Steals data from another column vector by swapping internal buffers.
* After steal(), 'other' is emptied and 'this' holds the original data from 'other'.
* Throws std::runtime_error if types are incompatible.
*/
virtual void steal(ColumnVector&& other) = 0;
Comment on lines +247 to +252
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Semantic contract mismatch between documentation and implementation.

The documentation states "After steal(), 'other' is emptied," but the implementations (lines 339-345, 411-417) only swap internal buffers without clearing other. After steal(), both vectors remain valid with swapped contents rather than other being empty. This violates the documented contract and could mislead callers who rely on other being emptied.

🔄 Proposed fix: clear 'other' after swapping

Update implementations to explicitly clear other after swapping:

 void steal(ColumnVector&& other) override {
     auto* other_num = dynamic_cast<NumericVector<T>*>(&other);
     if (!other_num) throw std::runtime_error("NumericVector::steal: type mismatch");
     data_.swap(other_num->data_);
     null_bitmap_.swap(other_num->null_bitmap_);
     std::swap(size_, other_num->size_);
+    other_num->data_.clear();
+    other_num->null_bitmap_.clear();
+    other_num->size_ = 0;
 }

Apply the same pattern to StringVector::steal at lines 411-417.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@include/executor/types.hpp` around lines 247 - 252, The doc for virtual void
steal(ColumnVector&& other) promises that 'other' is emptied after stealing but
current implementations only swap buffers; update each steal implementation
(e.g., ColumnVector::steal and StringVector::steal) to perform the swap and then
explicitly clear or reset the moved-from 'other' (call its clear/reset method,
set size/length to zero, and release/empty any auxiliary buffers) so that after
the call 'other' is empty while 'this' holds the original data; ensure you use
the class-specific clear/reset APIs to leave 'other' in a valid empty state.

};

/**
Expand Down Expand Up @@ -328,6 +335,14 @@ class NumericVector : public ColumnVector {
ColumnVector::clear();
data_.clear();
}

void steal(ColumnVector&& other) override {
auto* other_num = dynamic_cast<NumericVector<T>*>(&other);
if (!other_num) throw std::runtime_error("NumericVector::steal: type mismatch");
data_.swap(other_num->data_);
null_bitmap_.swap(other_num->null_bitmap_);
std::swap(size_, other_num->size_);
}
};

/**
Expand Down Expand Up @@ -392,6 +407,14 @@ class StringVector : public ColumnVector {
ColumnVector::clear();
data_.clear();
}

void steal(ColumnVector&& other) override {
auto* other_str = dynamic_cast<StringVector*>(&other);
if (!other_str) throw std::runtime_error("StringVector::steal: type mismatch");
data_.swap(other_str->data_);
null_bitmap_.swap(other_str->null_bitmap_);
std::swap(size_, other_str->size_);
}
};

/**
Expand Down
Loading