Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion be/benchmark/benchmark_column_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static ColumnPtr make_const_column() {
}

static ColumnPtr make_nullable_column() {
return ColumnNullable::create(make_plain_column()->assume_mutable(),
return ColumnNullable::create(make_plain_column()->assert_mutable(),
ColumnUInt8::create(NUM_ROWS, 0));
}

Expand Down
4 changes: 2 additions & 2 deletions be/src/core/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Vectorized columns (`IColumn`) use intrusive-reference-counted copy-on-write.
### Checkpoints

- [ ] Exclusive ownership guaranteed before `mutate()` on hot paths? Shared ownership triggers deep copy
- [ ] `assume_mutable_ref()` used only when exclusive ownership is already guaranteed?
- [ ] After `Block::mutate_columns()`, columns put back with `set_columns()`?
- [ ] `assert_mutable()` used only when exclusive ownership is already guaranteed?
- [ ] If you need to modify the data within a `Block`, have you correctly used `ScopedMutableBlock`?
- [ ] `convert_to_full_column_if_const()` materializes only `ColumnConst`; ordinary columns may return shared storage?

## Type System and Serialization
Expand Down
16 changes: 8 additions & 8 deletions be/src/core/block/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ void Block::clear_column_data(int64_t column_size) {
for (auto& d : data) {
if (d.column) {
if (d.column->is_exclusive()) {
d.column->assume_mutable()->clear();
d.column->assert_mutable()->clear();
} else {
d.column = d.column->clone_empty();
}
Expand All @@ -831,7 +831,7 @@ void Block::clear_column_data(const std::vector<uint32_t>& columns_to_clear) {
auto& column = data[col].column;
if (column) {
if (column->is_exclusive()) {
column->assume_mutable()->clear();
column->assert_mutable()->clear();
} else {
column = column->clone_empty();
}
Expand Down Expand Up @@ -894,15 +894,15 @@ void Block::filter_block_internal(Block* block, const std::vector<uint32_t>& col
}
if (count == 0) {
if (column->is_exclusive()) {
column->assume_mutable()->clear();
column->assert_mutable()->clear();
} else {
column = column->clone_empty();
}
continue;
}
if (column->is_exclusive()) {
// COW: safe to mutate in-place since we have exclusive ownership
const auto result_size = column->assume_mutable()->filter(filter);
const auto result_size = column->assert_mutable()->filter(filter);
if (result_size != count) [[unlikely]] {
throw Exception(ErrorCode::INTERNAL_ERROR,
"result_size not equal with filter_size, result_size={}, "
Expand Down Expand Up @@ -932,7 +932,7 @@ void Block::filter_block_internal(Block* block, const IColumn::Filter& filter) {
for (int i = 0; i < block->columns(); ++i) {
auto& column = block->get_by_position(i).column;
if (column->is_exclusive()) {
column->assume_mutable()->filter(filter);
column->assert_mutable()->filter(filter);
} else {
column = column->filter(filter, count);
}
Expand Down Expand Up @@ -961,7 +961,7 @@ Status Block::filter_block(Block* block, const std::vector<uint32_t>& columns_to

MutableColumnPtr mutable_holder =
nested_column->use_count() == 1
? nested_column->assume_mutable()
? nested_column->assert_mutable()
: nested_column->clone_resized(nested_column->size());

auto* concrete_column = assert_cast<ColumnUInt8*>(mutable_holder.get());
Expand All @@ -980,7 +980,7 @@ Status Block::filter_block(Block* block, const std::vector<uint32_t>& columns_to
for (const auto& col : columns_to_filter) {
auto& column = block->get_by_position(col).column;
if (column->is_exclusive()) {
column->assume_mutable()->clear();
column->assert_mutable()->clear();
} else {
column = column->clone_empty();
}
Expand Down Expand Up @@ -1263,7 +1263,7 @@ void Block::shrink_char_type_column_suffix_zero(const std::vector<size_t>& char_
if (idx < data.size()) {
auto& col_and_name = this->get_by_position(idx);
if (col_and_name.column->is_exclusive()) {
col_and_name.column->assume_mutable()->shrink_padding_chars();
col_and_name.column->assert_mutable()->shrink_padding_chars();
} else {
auto mutable_col = std::move(*col_and_name.column).mutate();
mutable_col->shrink_padding_chars();
Expand Down
2 changes: 1 addition & 1 deletion be/src/core/column/column_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ size_t ColumnMap::filter(const Filter& filter) {
static_cast<IColumn::Ptr&>(keys_column) = k_arr->get_data_ptr();
static_cast<IColumn::Ptr&>(offsets_column) = k_arr->get_offsets_ptr();
static_cast<IColumn::Ptr&>(values_column) = v_arr->get_data_ptr();
// Use const access to avoid assume_mutable_ref() on the just-written-back offsets_column
// Use const access to avoid assert_mutable_ref() on the just-written-back offsets_column
// (k_arr still holds a ref, so use_count > 1 until k_arr goes out of scope)
return static_cast<const IColumn::Ptr&>(offsets_column)->size();
}
Expand Down
2 changes: 1 addition & 1 deletion be/src/core/column/column_nullable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ size_t ColumnNullable::filter(const Filter& filter) {

Status ColumnNullable::filter_by_selector(const uint16_t* sel, size_t sel_size, IColumn* col_ptr) {
auto* nullable_col_ptr = assert_cast<ColumnNullable*>(col_ptr);
// Access the nested column via const path to avoid assume_mutable_ref (which requires
// Access the nested column via const path to avoid assert_mutable_ref (which requires
// exclusive ownership). The output col_ptr was just created, so its nested column is exclusive.
IColumn* nest_col_raw = const_cast<IColumn*>(
static_cast<const WrappedPtr&>(nullable_col_ptr->_nested_column).get());
Expand Down
4 changes: 2 additions & 2 deletions be/src/core/column/column_nullable.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class ColumnNullable final : public COWHelper<IColumn, ColumnNullable> {

const ColumnPtr& get_nested_column_ptr() const { return _nested_column; }

MutableColumnPtr get_nested_column_ptr() { return _nested_column->assume_mutable(); }
MutableColumnPtr get_nested_column_ptr() { return _nested_column->assert_mutable(); }

void clear() override {
_null_map->clear();
Expand Down Expand Up @@ -386,7 +386,7 @@ class ColumnNullable final : public COWHelper<IColumn, ColumnNullable> {
}
const NullMap& get_null_map_data() const { return get_null_map_column().get_data(); }

MutableColumnPtr get_null_map_column_ptr() { return _null_map->assume_mutable(); }
MutableColumnPtr get_null_map_column_ptr() { return _null_map->assert_mutable(); }
ColumnUInt8& get_null_map_column() {
return assert_cast<ColumnUInt8&, TypeCheckOnRelease::DISABLE>(*_null_map);
}
Expand Down
16 changes: 8 additions & 8 deletions be/src/core/cow.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class COW {
if (this->use_count() > 1) {
return derived()->clone();
} else {
return assume_mutable();
return assert_mutable();
}
}

Expand All @@ -320,17 +320,17 @@ class COW {
// uniquely owned. This does not detach shared owners; use a type-specific
// COW entry point (for example IColumn::mutate) when the pointer may be
// shared.
MutablePtr assume_mutable() const {
MutablePtr assert_mutable() const {
if (this->use_count() > 1) {
throw Exception(ErrorCode::INTERNAL_ERROR, "COW::assume_mutable: use_count() > 1");
throw Exception(ErrorCode::INTERNAL_ERROR, "COW::assert_mutable: use_count() > 1");
}
return const_cast<COW*>(this)->get_ptr();
}

// Reference variant of assume_mutable(), with the same ownership contract.
Derived& assume_mutable_ref() const {
// Reference variant of assert_mutable(), with the same ownership contract.
Derived& assert_mutable_ref() const {
if (this->use_count() > 1) {
throw Exception(ErrorCode::INTERNAL_ERROR, "COW::assume_mutable: use_count() > 1");
throw Exception(ErrorCode::INTERNAL_ERROR, "COW::assert_mutable: use_count() > 1");
}
return const_cast<Derived&>(*derived());
}
Expand All @@ -351,13 +351,13 @@ class COW {
: value(std::forward<std::initializer_list<U>>(arg)) {}

const T* get() const { return value.get(); }
T* get() { return &value->assume_mutable_ref(); }
T* get() { return &value->assert_mutable_ref(); }

const T* operator->() const { return get(); }
T* operator->() { return get(); }

const T& operator*() const { return *value; }
T& operator*() { return value->assume_mutable_ref(); }
T& operator*() { return value->assert_mutable_ref(); }

operator const immutable_ptr<T>&() const { return value; }
operator immutable_ptr<T>&() { return value; }
Expand Down
2 changes: 1 addition & 1 deletion be/src/exec/common/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ inline void change_null_to_true(MutableColumnPtr column, ColumnPtr argument = nu
size_t rows = column->size();
if (is_column_const(*column)) {
change_null_to_true(
assert_cast<ColumnConst*>(column.get())->get_data_column_ptr()->assume_mutable());
assert_cast<ColumnConst*>(column.get())->get_data_column_ptr()->assert_mutable());
} else if (column->has_null()) {
auto* nullable = assert_cast<ColumnNullable*>(column.get());
auto* __restrict data = assert_cast<ColumnUInt8*>(nullable->get_nested_column_ptr().get())
Expand Down
2 changes: 1 addition & 1 deletion be/src/exec/operator/aggregation_source_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ Status AggLocalState::_get_without_key_result(RuntimeState* state, Block* block,
// unless `count`, other aggregate function dispose empty set should be null
// so here check the children row return
ptr = make_nullable(ptr, shared_state.input_num_rows == 0);
columns[i] = ptr->assume_mutable();
columns[i] = ptr->assert_mutable();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion be/src/exec/operator/assert_num_rows_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Status AssertNumRowsOperatorX::pull(doris::RuntimeState* state, Block* block, bo
auto& type = block->get_by_position(i).type;
type = make_nullable(type);
column = type->create_column();
column->assume_mutable()->insert_default();
column->assert_mutable()->insert_default();
}
assert_res = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ Status DistinctStreamingAggLocalState::_distinct_pre_agg_with_serialized_key(
// swap the column directly, to solve Check failed: d.column->use_count() == 1 (2 vs. 1)
for (int i = 0; i < key_size; ++i) {
auto output_column = out_block->get_by_position(i).column;
out_block->replace_by_position(i, key_columns[i]->assume_mutable());
out_block->replace_by_position(i, key_columns[i]->assert_mutable());
in_block->replace_by_position(result_idxs[i], output_column);
}
} else {
Expand Down Expand Up @@ -240,7 +240,7 @@ Status DistinctStreamingAggLocalState::_distinct_pre_agg_with_serialized_key(
ColumnsWithTypeAndName columns_with_schema;
for (int i = 0; i < key_size; ++i) {
if (_stop_emplace_flag) {
columns_with_schema.emplace_back(key_columns[i]->assume_mutable(),
columns_with_schema.emplace_back(key_columns[i]->assert_mutable(),
_probe_expr_ctxs[i]->root()->data_type(),
_probe_expr_ctxs[i]->root()->expr_name());
} else {
Expand Down
4 changes: 2 additions & 2 deletions be/src/exec/operator/hashjoin_build_sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ size_t HashJoinBuildSinkLocalState::get_reserve_mem_size(RuntimeState* state, bo
// first row is mocked
for (int i = 0; i < block.columns(); i++) {
auto [column, is_const] = unpack_if_const(block.safe_get_by_position(i).column);
assert_cast<ColumnNullable*>(column->assume_mutable().get())
assert_cast<ColumnNullable*>(column->assert_mutable().get())
->get_null_map_column()
.get_data()
.data()[0] = 1;
Expand Down Expand Up @@ -590,7 +590,7 @@ Status HashJoinBuildSinkLocalState::process_build_block(RuntimeState* state, Blo
// first row is mocked
for (int i = 0; i < block.columns(); i++) {
auto [column, is_const] = unpack_if_const(block.safe_get_by_position(i).column);
assert_cast<ColumnNullable*>(column->assume_mutable().get())
assert_cast<ColumnNullable*>(column->assert_mutable().get())
->get_null_map_column()
.get_data()
.data()[0] = 1;
Expand Down
2 changes: 1 addition & 1 deletion be/src/exec/operator/join/process_hash_table_probe_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ Status ProcessHashTableProbe<JoinOpType>::do_other_join_conjuncts(Block* output_
output_block->insert({std::move(filter_column), std::make_shared<DataTypeUInt8>(), ""});
uint8_t* __restrict filter_column_ptr =
assert_cast<ColumnUInt8&>(
output_block->get_by_position(result_column_id).column->assume_mutable_ref())
output_block->get_by_position(result_column_id).column->assert_mutable_ref())
.get_data()
.data();

Expand Down
2 changes: 1 addition & 1 deletion be/src/exec/operator/nested_loop_join_probe_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class NestedLoopJoinProbeLocalState final
for (size_t i = 0; i < column_to_keep; ++i) { \
auto& column = block->get_by_position(i).column; \
if (column->is_exclusive()) { \
column->assume_mutable()->clear(); \
column->assert_mutable()->clear(); \
} else { \
column = column->clone_empty(); \
} \
Expand Down
4 changes: 2 additions & 2 deletions be/src/exec/operator/operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,14 @@ Status OperatorXBase::do_projections(RuntimeState* state, Block* origin_block,
null_column.get_null_map_column().get_data().resize_fill(rows, 0);
bytes_usage += null_column.allocated_bytes();
} else {
to = make_nullable(from, false)->assume_mutable();
to = make_nullable(from, false)->assert_mutable();
}
} else {
if (_keep_origin || !from->is_exclusive()) {
to->insert_range_from(*from, 0, rows);
bytes_usage += from->allocated_bytes();
} else {
to = from->assume_mutable();
to = from->assert_mutable();
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion be/src/exec/rowid_fetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ Status RowIdStorageReader::read_by_rowids(const PMultiGetRequest& request,
for (int x = 0; x < slots.size(); ++x) {
std::vector<segment_v2::rowid_t> row_ids {
static_cast<segment_v2::rowid_t>(row_loc.ordinal_id())};
MutableColumnPtr column = result_block.get_by_position(x).column->assume_mutable();
MutableColumnPtr column = result_block.get_by_position(x).column->assert_mutable();
IteratorKey iterator_key {.tablet_id = tablet->tablet_id(),
.rowset_id = rowset_id,
.segment_id = row_loc.segment_id(),
Expand Down
4 changes: 2 additions & 2 deletions be/src/exec/sort/sorter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,12 @@ Status FullSorter::append_block(Block* block) {
<< " type1: " << data[i].type->get_name()
<< " type2: " << arrival_data[i].type->get_name() << " i: " << i;
if (is_column_const(*arrival_data[i].column)) {
data[i].column->assume_mutable()->insert_many_from(
data[i].column->assert_mutable()->insert_many_from(
assert_cast<const ColumnConst*>(arrival_data[i].column.get())
->get_data_column(),
0, sz);
} else {
data[i].column->assume_mutable()->insert_range_from(*arrival_data[i].column, 0, sz);
data[i].column->assert_mutable()->insert_range_from(*arrival_data[i].column, 0, sz);
}
}
block->clear_column_data();
Expand Down
4 changes: 2 additions & 2 deletions be/src/exprs/aggregate/aggregate_function_null_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class AggregateFunctionNullBaseInlineV2 : public IAggregateFunctionHelper<Derive
auto& nullable_col = assert_cast<ColumnNullable&>(*dst);
auto& nested_col = nullable_col.get_nested_column();
auto& null_map = nullable_col.get_null_map_data();
MutableColumnPtr nested_col_ptr = nested_col.assume_mutable();
MutableColumnPtr nested_col_ptr = nested_col.assert_mutable();

null_map.resize(num_rows);
uint8_t* __restrict null_map_data = null_map.data();
Expand Down Expand Up @@ -273,7 +273,7 @@ class AggregateFunctionNullBaseInlineV2 : public IAggregateFunctionHelper<Derive

if constexpr (result_is_nullable) {
auto& dst_nullable_col = assert_cast<ColumnNullable&>(*dst);
MutableColumnPtr nested_col_ptr = dst_nullable_col.get_nested_column().assume_mutable();
MutableColumnPtr nested_col_ptr = dst_nullable_col.get_nested_column().assert_mutable();
dst_nullable_col.get_null_map_column().insert_range_from(
src_nullable_col->get_null_map_column(), 0, num_rows);
nested_function->serialize_to_column(nested_places, 0, nested_col_ptr, num_rows);
Expand Down
12 changes: 6 additions & 6 deletions be/src/exprs/function/array/function_array_aggregation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ struct ArrayAggregateImpl {

ColumnPtr res_column = create_column_func(column);
res_column = make_nullable(res_column);
assert_cast<ColumnNullable&>(res_column->assume_mutable_ref()).reserve(offsets.size());
assert_cast<ColumnNullable&>(res_column->assert_mutable_ref()).reserve(offsets.size());

auto function = Function::create(type, {.is_window_function = false, .column_names = {}});
auto guard = AggregateFunctionGuard(function.get());
Expand All @@ -228,13 +228,13 @@ struct ArrayAggregateImpl {
auto end = offsets[i];
bool is_empty = (start == end);
if (is_empty) {
res_column->assume_mutable()->insert_default();
res_column->assert_mutable()->insert_default();
continue;
}
function->reset(guard.data());
function->add_batch_range(start, end - 1, guard.data(), columns, arena,
data->is_nullable());
function->insert_result_into(guard.data(), res_column->assume_mutable_ref());
function->insert_result_into(guard.data(), res_column->assert_mutable_ref());
}
res_ptr = std::move(res_column);
return true;
Expand Down Expand Up @@ -440,7 +440,7 @@ struct ArrayAggregateImplDecimalV3<operation, ResultType> {

ColumnPtr res_column = create_column_func(column);
res_column = make_nullable(res_column);
assert_cast<ColumnNullable&>(res_column->assume_mutable_ref()).reserve(offsets.size());
assert_cast<ColumnNullable&>(res_column->assert_mutable_ref()).reserve(offsets.size());

auto function = Function::create(type, result_type,
{.is_window_function = false, .column_names = {}});
Expand All @@ -453,13 +453,13 @@ struct ArrayAggregateImplDecimalV3<operation, ResultType> {
auto end = offsets[i];
bool is_empty = (start == end);
if (is_empty) {
res_column->assume_mutable()->insert_default();
res_column->assert_mutable()->insert_default();
continue;
}
function->reset(guard.data());
function->add_batch_range(start, end - 1, guard.data(), columns, arena,
data->is_nullable());
function->insert_result_into(guard.data(), res_column->assume_mutable_ref());
function->insert_result_into(guard.data(), res_column->assert_mutable_ref());
}
res_ptr = std::move(res_column);
return true;
Expand Down
Loading
Loading