Skip to content

Commit

Permalink
[Fix](ShortCircuit) consider delete sign flag when hits row
Browse files Browse the repository at this point in the history
If partial update with delete clause, the new rowset delete sign should be considered
  • Loading branch information
eldenmoon committed Sep 3, 2024
1 parent a1ea5c4 commit df1890b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
18 changes: 18 additions & 0 deletions be/src/service/point_query_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
#include "runtime/thread_context.h"
#include "util/key_util.h"
#include "util/runtime_profile.h"
#include "util/simd/bits.h"
#include "util/thrift_util.h"
#include "vec/columns/columns_number.h"
#include "vec/data_types/serde/data_type_serde.h"
#include "vec/exprs/vexpr.h"
#include "vec/exprs/vexpr_context.h"
Expand Down Expand Up @@ -143,6 +145,9 @@ Status Reusable::init(const TDescriptorTable& t_desc_tbl, const std::vector<TExp
extract_slot_ref(expr->root(), tuple_desc(), output_slot_descs);
}

// get the delete sign idx in block
_delete_sign_idx = _col_uid_to_idx[schema.columns()[schema.delete_sign_idx()]->unique_id()];

if (schema.have_column(BeConsts::ROW_STORE_COL)) {
const auto& column = *DORIS_TRY(schema.column(BeConsts::ROW_STORE_COL));
_row_store_column_ids = column.unique_id();
Expand Down Expand Up @@ -483,6 +488,19 @@ Status PointQueryExecutor::_lookup_row_data() {
}
}
}
// filter rows by delete sign
if (_row_hits > 0 && _reusable->delete_sign_idx() != -1) {
vectorized::ColumnPtr delete_filter_columns =
_result_block->get_columns()[_reusable->delete_sign_idx()];
const auto& filter =
assert_cast<const vectorized::ColumnInt8*>(delete_filter_columns.get())->get_data();
size_t count = filter.size() - simd::count_zero_num((int8_t*)filter.data(), filter.size());
if (count == filter.size()) {
_result_block->clear();
} else if (count > 0) {
return Status::NotSupported("Not implemented since only single row at present");
}
}
return Status::OK();
}

Expand Down
5 changes: 5 additions & 0 deletions be/src/service/point_query_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ class Reusable {

RuntimeState* runtime_state() { return _runtime_state.get(); }

// delete sign idx in block
int32_t delete_sign_idx() const { return _delete_sign_idx; }

private:
// caching TupleDescriptor, output_expr, etc...
std::unique_ptr<RuntimeState> _runtime_state;
Expand All @@ -118,6 +121,8 @@ class Reusable {
std::unordered_set<int32_t> _missing_col_uids;
// included cids in rowstore(column group)
std::unordered_set<int32_t> _include_col_uids;
// delete sign idx in block
int32_t _delete_sign_idx = -1;
};

// RowCache is a LRU cache for row store
Expand Down
8 changes: 8 additions & 0 deletions regression-test/data/point_query_p0/test_point_query.out
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,11 @@
-- !sql --
0 1111111

-- !sql --
10 20 aabc value

-- !sql --

-- !sql --
-10 20 aabc update val

27 changes: 27 additions & 0 deletions regression-test/suites/point_query_p0/test_point_query.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,31 @@ suite("test_point_query", "nonConcurrent") {
sql """set global enable_nereids_planner=true"""
sql "set global enable_fallback_to_original_planner = true"
}

// test partial update/delete
sql "DROP TABLE IF EXISTS table_3821461"
sql """
CREATE TABLE `table_3821461` (
`col1` smallint NOT NULL,
`col2` int NOT NULL,
`loc3` char(10) NOT NULL,
`value` char(10) NOT NULL,
INDEX col3 (`loc3`) USING INVERTED,
INDEX col2 (`col2`) USING INVERTED )
ENGINE=OLAP UNIQUE KEY(`col1`, `col2`, `loc3`)
DISTRIBUTED BY HASH(`col1`, `col2`, `loc3`) BUCKETS 1
PROPERTIES ( "replication_allocation" = "tag.location.default: 1", "bloom_filter_columns" = "col1", "store_row_column" = "true" );
"""
sql "insert into table_3821461 values (-10, 20, 'aabc', 'value')"
sql "insert into table_3821461 values (10, 20, 'aabc', 'value');"
sql "insert into table_3821461 values (20, 30, 'aabc', 'value');"
explain {
sql("select * from table_3821461 where col1 = -10 and col2 = 20 and loc3 = 'aabc'")
contains "SHORT-CIRCUIT"
}
qt_sql "select * from table_3821461 where col1 = 10 and col2 = 20 and loc3 = 'aabc';"
sql "delete from table_3821461 where col1 = 10 and col2 = 20 and loc3 = 'aabc';"
qt_sql "select * from table_3821461 where col1 = 10 and col2 = 20 and loc3 = 'aabc';"
sql "update table_3821461 set value = 'update value' where col1 = -10 or col1 = 20;"
qt_sql """select * from table_3821461 where col1 = -10 and col2 = 20 and loc3 = 'aabc'"""
}

0 comments on commit df1890b

Please sign in to comment.