Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug][Vectorized] Fix BE crash with delete condition and enable_storage_vectorization #9547

Merged
merged 1 commit into from
May 17, 2022
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
41 changes: 28 additions & 13 deletions be/src/olap/rowset/segment_v2/segment_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,9 @@ void SegmentIterator::_init_current_block(
auto cid = _schema.column_id(i);
auto column_desc = _schema.column(cid);

if (_is_pred_column[cid]) { //todo(wb) maybe we can release it after output block
// the column in in block must clear() here to insert new data
if (_is_pred_column[cid] ||
HappenLee marked this conversation as resolved.
Show resolved Hide resolved
i >= block->columns()) { //todo(wb) maybe we can release it after output block
current_columns[cid]->clear();
} else { // non-predicate column
current_columns[cid] = std::move(*block->get_by_position(i).column).mutate();
Expand All @@ -815,8 +817,12 @@ void SegmentIterator::_init_current_block(
void SegmentIterator::_output_non_pred_columns(vectorized::Block* block) {
SCOPED_RAW_TIMER(&_opts.stats->output_col_ns);
for (auto cid : _non_predicate_columns) {
block->replace_by_position(_schema_block_id_map[cid],
std::move(_current_return_columns[cid]));
auto loc = _schema_block_id_map[cid];
HappenLee marked this conversation as resolved.
Show resolved Hide resolved
// if loc < block->block->columns() means the the column is delete column and should
// not output by block, so just skip the column.
if (loc < block->columns()) {
block->replace_by_position(loc, std::move(_current_return_columns[cid]));
}
}
}

Expand Down Expand Up @@ -950,15 +956,24 @@ Status SegmentIterator::next_batch(vectorized::Block* block) {
_block_rowids.resize(_opts.block_row_max);
}
_current_return_columns.resize(_schema.columns().size());
if (_is_need_vec_eval || _is_need_short_eval) {
for (size_t i = 0; i < _schema.num_column_ids(); i++) {
auto cid = _schema.column_id(i);
if (_is_pred_column[cid]) {
auto column_desc = _schema.column(cid);
_current_return_columns[cid] = Schema::get_predicate_column_nullable_ptr(
column_desc->type(), column_desc->is_nullable());
_current_return_columns[cid]->reserve(_opts.block_row_max);
}
for (size_t i = 0; i < _schema.num_column_ids(); i++) {
auto cid = _schema.column_id(i);
auto column_desc = _schema.column(cid);
if (_is_pred_column[cid]) {
_current_return_columns[cid] = Schema::get_predicate_column_nullable_ptr(
column_desc->type(), column_desc->is_nullable());
_current_return_columns[cid]->reserve(_opts.block_row_max);
} else if (i >= block->columns()) {
// if i >= block->columns means the column and not the pred_column means `column i` is
// a delete condition column. but the column is not effective in the segment. so we just
// create a column to hold the data.
// a. origin data -> b. delete condition -> c. new load data
// the segment of c do not effective delete condition, but it still need read the column
// to match the schema.
// TODO: skip read the not effective delete column to speed up segment read.
_current_return_columns[cid] =
Schema::get_data_type_ptr(*column_desc)->create_column();
_current_return_columns[cid]->reserve(_opts.block_row_max);
}
}
}
Expand All @@ -973,7 +988,7 @@ Status SegmentIterator::next_batch(vectorized::Block* block) {
_opts.stats->raw_rows_read += nrows_read;

if (nrows_read == 0) {
for (int i = 0; i < _schema.num_column_ids(); i++) {
for (int i = 0; i < block->columns(); i++) {
auto cid = _schema.column_id(i);
// todo(wb) abstract make column where
if (!_is_pred_column[cid]) { // non-predicate
Expand Down
16 changes: 16 additions & 0 deletions regression-test/data/delete/test_delete.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
8

-- !sql --
8

-- !sql --
8

-- !sql --
8

-- !sql --
8

17 changes: 15 additions & 2 deletions regression-test/suites/delete/test_delete.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@
// under the License.

suite("test_delete", "delete") {
// todo: test delete
sql "show delete"
def tableName = "delete_regression_test"

sql """ DROP TABLE IF EXISTS ${tableName} """
sql """ CREATE TABLE ${tableName} (c1 varchar(190) NOT NULL COMMENT "",c2 bigint(20) NOT NULL COMMENT "", c3 varchar(160) NULL COMMENT "" ) ENGINE=OLAP DUPLICATE KEY(c1, c2) COMMENT "OLAP" DISTRIBUTED BY HASH(c3) BUCKETS 3
PROPERTIES ( "replication_num" = "1" );"""

sql """INSERT INTO ${tableName} VALUES ('abcdef',1,'fjdsajfldjafljdslajfdl'),('abcdef',2,'fjdsajfldjafljdslajfdl'),('abcdef',4,'fjdsajfldjafljdslajfdl'),('abcdef',5,'fjdsajfldjafljdslajfdl')"""
sql """delete from ${tableName} where c1 = 'fjdsajfldjafljdslajfdl';"""
sql """INSERT INTO ${tableName} VALUES ('abcdef',1,'fjdsajfldjafljdslajfdl'),('abcdef',2,'fjdsajfldjafljdslajfdl'),('abcdef',4,'fjdsajfldjafljdslajfdl'),('abcdef',5,'fjdsajfldjafljdslajfdl');"""

qt_sql """select count(*) from ${tableName};"""
qt_sql """select count(c2) from ${tableName};"""
qt_sql """select count(c2) from ${tableName} where c1 = 'abcdef';"""
qt_sql """select count(c1) from ${tableName};"""
qt_sql """select count(c1) from ${tableName} where c1 = 'abcdef';"""
}