@@ -86,8 +86,6 @@ Status PrimaryKeyModelRowRetriever::retrieve_historical_row(const Int8* delete_s
8686 auto * tablet = static_cast <Tablet*>(_context.tablet .get ());
8787 auto & tablet_schema = _context.tablet_schema ;
8888
89- DCHECK (_context.partial_update_info );
90-
9189 std::vector<RowsetSharedPtr> specified_rowsets;
9290 {
9391 std::shared_lock rlock (_context.tablet ->get_header_lock ());
@@ -169,7 +167,7 @@ Status PrimaryKeyModelRowRetriever::build_after_block(Block* block, size_t row_p
169167 }
170168 return _rssid_to_rid.fill_missing_columns (
171169 _context, _rsid_to_rowset, *_context.tablet_schema , *block, _use_default_or_null_flag,
172- _has_default_or_nullable, cast_set<uint32_t >(row_pos), block);
170+ _has_default_or_nullable, cast_set<uint32_t >(row_pos), block, &_old_delete_signs );
173171}
174172
175173Status PrimaryKeyModelRowRetriever::build_before_block (Block* before_block,
@@ -193,17 +191,18 @@ Status PrimaryKeyModelRowRetriever::build_before_block(Block* before_block,
193191 // key: logical row index in current batch; value: index in old_value_block
194192 std::map<uint32_t , uint32_t > read_index;
195193 RETURN_IF_ERROR (_rssid_to_rid.read_columns_by_plan (*tablet_schema, value_cids, _rsid_to_rowset,
196- old_value_block, &read_index, false ,
194+ old_value_block, &read_index, true ,
197195 nullptr ));
196+ RETURN_IF_ERROR (_fill_old_delete_signs (old_value_block, read_index, num_rows));
198197
199198 {
200199 auto mutable_before_columns_guard = before_block->mutate_columns_scoped ();
201200 auto & mutable_before_columns = mutable_before_columns_guard.mutable_columns ();
202201 // Fill each row in before_block.
203202 for (uint32_t idx = 0 ; idx < num_rows; ++idx) {
204203 auto it = read_index.find (idx);
205- if (it == read_index.end ()) {
206- // No historical row, fill BEFORE with NULL.
204+ if (it == read_index.end () || _old_delete_signs[idx] != 0 ) {
205+ // No live historical row, fill BEFORE with NULL.
207206 for (size_t i = 0 ; i < value_cids.size (); ++i) {
208207 auto * nullable_column =
209208 assert_cast<ColumnNullable*>(mutable_before_columns[i].get ());
@@ -223,6 +222,38 @@ Status PrimaryKeyModelRowRetriever::build_before_block(Block* before_block,
223222 return Status::OK ();
224223}
225224
225+ Status PrimaryKeyModelRowRetriever::revise_operators_by_old_delete_sign (size_t num_rows) {
226+ if (_operators.empty () || _rssid_to_rid.empty ()) {
227+ return Status::OK ();
228+ }
229+ DCHECK_EQ (_operators.size (), num_rows);
230+
231+ if (_old_delete_signs.empty ()) {
232+ // If no BEFORE/missing column was read, read only old delete signs here.
233+ Block old_delete_sign_block;
234+ std::map<uint32_t , uint32_t > read_index;
235+ RETURN_IF_ERROR (_rssid_to_rid.read_columns_by_plan (
236+ *_context.tablet_schema , std::vector<uint32_t > {}, _rsid_to_rowset,
237+ old_delete_sign_block, &read_index, true , nullptr ));
238+ RETURN_IF_ERROR (_fill_old_delete_signs (old_delete_sign_block, read_index, num_rows));
239+ }
240+ DCHECK_EQ (_old_delete_signs.size (), num_rows);
241+
242+ for (size_t idx = 0 ; idx < num_rows; ++idx) {
243+ if (_operators[idx] == ROW_BINLOG_UPDATE && _old_delete_signs[idx] != 0 ) {
244+ _operators[idx] = ROW_BINLOG_APPEND ;
245+ }
246+ }
247+ return Status::OK ();
248+ }
249+
250+ Status PrimaryKeyModelRowRetriever::_fill_old_delete_signs (
251+ const Block& old_value_block, const std::map<uint32_t , uint32_t >& read_index,
252+ size_t num_rows) {
253+ return _rssid_to_rid.fill_old_delete_signs (old_value_block, read_index, num_rows,
254+ &_old_delete_signs);
255+ }
256+
226257std::string PrimaryKeyModelRowRetriever::_full_encode_keys (
227258 const std::vector<IOlapColumnDataAccessor*>& key_columns, size_t pos, bool null_first) {
228259 return _full_encode_keys (_key_coders, key_columns, pos, null_first);
0 commit comments