24
24
#include " olap/olap_common.h"
25
25
#include " olap/rowset/rowset.h"
26
26
#include " olap/rowset/rowset_writer_context.h"
27
- #include " olap/tablet_meta.h"
28
27
#include " olap/tablet_schema.h"
29
28
#include " olap/utils.h"
30
29
#include " util/bitmap_value.h"
@@ -206,9 +205,21 @@ void PartialUpdateReadPlan::prepare_to_read(const RowLocation& row_location, siz
206
205
// read columns by read plan
207
206
// read_index: ori_pos-> block_idx
208
207
Status PartialUpdateReadPlan::read_columns_by_plan (
209
- const TabletSchema& tablet_schema, const std::vector<uint32_t > cids_to_read,
208
+ const TabletSchema& tablet_schema, std::vector<uint32_t > cids_to_read,
210
209
const std::map<RowsetId, RowsetSharedPtr>& rsid_to_rowset, vectorized::Block& block,
211
- std::map<uint32_t , uint32_t >* read_index, const signed char * __restrict skip_map) const {
210
+ std::map<uint32_t , uint32_t >* read_index, bool force_read_old_delete_signs,
211
+ const signed char * __restrict cur_delete_signs) const {
212
+ if (force_read_old_delete_signs) {
213
+ // always read delete sign column from historical data
214
+ if (const vectorized::ColumnWithTypeAndName* old_delete_sign_column =
215
+ block.try_get_by_name (DELETE_SIGN);
216
+ old_delete_sign_column == nullptr ) {
217
+ auto del_col_cid = tablet_schema.field_index (DELETE_SIGN);
218
+ cids_to_read.emplace_back (del_col_cid);
219
+ block.swap (tablet_schema.create_block_by_cids (cids_to_read));
220
+ }
221
+ }
222
+
212
223
bool has_row_column = tablet_schema.has_row_store_for_all_columns ();
213
224
auto mutable_columns = block.mutate_columns ();
214
225
size_t read_idx = 0 ;
@@ -218,7 +229,7 @@ Status PartialUpdateReadPlan::read_columns_by_plan(
218
229
CHECK (rowset_iter != rsid_to_rowset.end ());
219
230
std::vector<uint32_t > rids;
220
231
for (auto [rid, pos] : mappings) {
221
- if (skip_map && skip_map [pos]) {
232
+ if (cur_delete_signs && cur_delete_signs [pos]) {
222
233
continue ;
223
234
}
224
235
rids.emplace_back (rid);
@@ -263,17 +274,15 @@ Status PartialUpdateReadPlan::fill_missing_columns(
263
274
// record real pos, key is input line num, value is old_block line num
264
275
std::map<uint32_t , uint32_t > read_index;
265
276
RETURN_IF_ERROR (read_columns_by_plan (tablet_schema, missing_cids, rsid_to_rowset,
266
- old_value_block, &read_index, nullptr ));
267
-
268
- const auto * delete_sign_column_data = BaseTablet::get_delete_sign_column_data (old_value_block);
277
+ old_value_block, &read_index, true , nullptr ));
269
278
279
+ const auto * old_delete_signs = BaseTablet::get_delete_sign_column_data (old_value_block);
280
+ DCHECK (old_delete_signs != nullptr );
270
281
// build default value columns
271
282
auto default_value_block = old_value_block.clone_empty ();
272
- if (has_default_or_nullable || delete_sign_column_data != nullptr ) {
273
- RETURN_IF_ERROR (BaseTablet::generate_default_value_block (
274
- tablet_schema, missing_cids, rowset_ctx->partial_update_info ->default_values ,
275
- old_value_block, default_value_block));
276
- }
283
+ RETURN_IF_ERROR (BaseTablet::generate_default_value_block (
284
+ tablet_schema, missing_cids, rowset_ctx->partial_update_info ->default_values ,
285
+ old_value_block, default_value_block));
277
286
auto mutable_default_value_columns = default_value_block.mutate_columns ();
278
287
279
288
// fill all missing value from mutable_old_columns, need to consider default value and null value
@@ -285,8 +294,8 @@ Status PartialUpdateReadPlan::fill_missing_columns(
285
294
// read values from old rows for missing values in this occasion. So we should read the DELETE_SIGN column
286
295
// to check if a row REALLY exists in the table.
287
296
auto pos_in_old_block = read_index[idx + segment_start_pos];
288
- if (use_default_or_null_flag[idx] || (delete_sign_column_data != nullptr &&
289
- delete_sign_column_data [pos_in_old_block] != 0 )) {
297
+ if (use_default_or_null_flag[idx] ||
298
+ (old_delete_signs != nullptr && old_delete_signs [pos_in_old_block] != 0 )) {
290
299
for (auto i = 0 ; i < missing_cids.size (); ++i) {
291
300
// if the column has default value, fill it with default value
292
301
// otherwise, if the column is nullable, fill it with null value
0 commit comments