diff --git a/src/storage/blocksstable/encoding/ob_imicro_block_decoder.h b/src/storage/blocksstable/encoding/ob_imicro_block_decoder.h index 82144c1795..e180fb6a7c 100644 --- a/src/storage/blocksstable/encoding/ob_imicro_block_decoder.h +++ b/src/storage/blocksstable/encoding/ob_imicro_block_decoder.h @@ -30,7 +30,7 @@ public: ObIMicroBlockDecoder() : ObIMicroBlockReader() {} virtual ~ObIMicroBlockDecoder() {} virtual int compare_rowkey( - const ObDatumRowkey &rowkey, const int64_t index, int32_t &compare_result) = 0; + const ObDatumRowkey &rowkey, const int64_t index, int32_t &compare_result) override = 0; virtual int compare_rowkey(const ObDatumRange &range, const int64_t index, int32_t &start_key_compare_result, int32_t &end_key_compare_result) = 0; diff --git a/src/storage/blocksstable/index_block/ob_ddl_index_block_row_iterator.cpp b/src/storage/blocksstable/index_block/ob_ddl_index_block_row_iterator.cpp index b819ac4d3f..a3f1bd13b2 100644 --- a/src/storage/blocksstable/index_block/ob_ddl_index_block_row_iterator.cpp +++ b/src/storage/blocksstable/index_block/ob_ddl_index_block_row_iterator.cpp @@ -11,6 +11,7 @@ */ #define USING_LOG_PREFIX STORAGE +#include "storage/access/ob_rows_info.h" #include "storage/blocksstable/index_block/ob_ddl_index_block_row_iterator.h" #include "storage/ddl/ob_tablet_ddl_kv.h" #include "storage/ls/ob_ls.h" @@ -64,7 +65,6 @@ int ObDDLIndexBlockRowIterator::init(const ObMicroBlockData &idx_block_data, const ObStorageDatumUtils *datum_utils, ObIAllocator *allocator, const bool is_reverse_scan, - const bool set_iter_end, const ObIndexBlockIterParam &iter_param) { int ret = OB_SUCCESS; @@ -177,6 +177,113 @@ int ObDDLIndexBlockRowIterator::locate_range(const ObDatumRange &range, return ret; } +int ObDDLIndexBlockRowIterator::locate_range() +{ + int ret = OB_SUCCESS; + ObDatumRange range; + range.set_start_key(ObDatumRowkey::MIN_ROWKEY); + range.set_end_key(ObDatumRowkey::MAX_ROWKEY); + range.set_left_open(); + range.set_right_open(); + if (IS_NOT_INIT) { + ret = OB_NOT_INIT; + LOG_WARN("Iter not opened yet", K(ret), KPC(this)); + } else if (OB_ISNULL(block_meta_tree_)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("block meta tree is null", K(ret)); + } else if (OB_FAIL(block_meta_tree_->locate_range(range, + *datum_utils_, + false, /*is_left_border*/ + false, /*is_right_border*/ + is_reverse_scan_, + btree_iter_, + cur_tree_value_))) { + if (OB_BEYOND_THE_RANGE != ret) { + LOG_WARN("block meta tree locate range failed", K(ret), K(range)); + } else { + is_iter_finish_ = true; + LOG_INFO("no data to locate", K(ret)); + ret = OB_SUCCESS; + } + } else if (OB_ISNULL(cur_tree_value_)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("cur tree value is null", K(ret), KP(cur_tree_value_)); + } else { + is_iter_start_ = true; + is_iter_finish_ = false; + } + return ret; +} + +int ObDDLIndexBlockRowIterator::skip_to_next_valid_position(const ObDatumRowkey &rowkey) +{ + int ret = OB_SUCCESS; + storage::ObBlockMetaTreeValue *tmp_tree_value = nullptr; + if (IS_NOT_INIT) { + ret = OB_NOT_INIT; + LOG_WARN("Iter not opened yet", K(ret), KPC(this)); + } else if (OB_ISNULL(block_meta_tree_)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("block meta tree is null", K(ret)); + } else if (OB_FAIL(block_meta_tree_->skip_to_next_valid_position(rowkey, + *datum_utils_, + btree_iter_, + tmp_tree_value))) { + if (OB_UNLIKELY(OB_ITER_END != ret)) { + LOG_WARN("Failed to skip to next valid position in block meta tree", K(ret), K(rowkey)); + } else { + is_iter_finish_ = true; + } + } else { + cur_tree_value_ = tmp_tree_value; + } + return ret; +} + +int ObDDLIndexBlockRowIterator::find_rowkeys_belong_to_same_idx_row(ObMicroIndexInfo &idx_block_row, int64_t &rowkey_begin_idx, int64_t &rowkey_end_idx, const ObRowsInfo *&rows_info) +{ + int ret = OB_SUCCESS; + if (IS_NOT_INIT) { + ret = OB_NOT_INIT; + LOG_WARN("Iter not opened yet", K(ret), KPC(this)); + } else if (OB_ISNULL(rows_info)) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid rows info", K(ret)); + } else { + const ObDatumRowkey *cur_rowkey = cur_rowkey = cur_tree_value_->rowkey_;; + bool is_decided = false; + for (; OB_SUCC(ret) && rowkey_begin_idx < rowkey_end_idx; ++rowkey_begin_idx) { + if (rows_info->is_row_skipped(rowkey_begin_idx)) { + continue; + } + const ObDatumRowkey &rowkey = rows_info->get_rowkey(rowkey_begin_idx); + int32_t cmp_ret = 0; + if (OB_ISNULL(cur_rowkey)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("null rowkey", K(ret), K(cur_tree_value_), KP(cur_rowkey)); + } else if (OB_FAIL(rowkey.compare(*cur_rowkey, *datum_utils_, cmp_ret, false))) { + LOG_WARN("Failed to compare rowkey", K(ret), K(rowkey), KPC(cur_rowkey)); + } + + if (OB_FAIL(ret)) { + } else if (cmp_ret > 0) { + idx_block_row.rowkey_end_idx_ = rowkey_begin_idx; + is_decided = true; + break; + } else if (cmp_ret == 0) { + idx_block_row.rowkey_end_idx_ = rowkey_begin_idx + 1; + is_decided = true; + break; + } + } + + if (OB_SUCC(ret) && !is_decided) { + idx_block_row.rowkey_end_idx_ = rowkey_begin_idx; + } + } + return ret; +} + int ObDDLIndexBlockRowIterator::check_blockscan(const ObDatumRowkey &rowkey, bool &can_blockscan) { int ret = OB_SUCCESS; @@ -404,7 +511,6 @@ int ObDDLSStableAllRangeIterator::init(const ObMicroBlockData &idx_block_data, const ObStorageDatumUtils *datum_utils, ObIAllocator *allocator, const bool is_reverse_scan, - const bool set_iter_end, const ObIndexBlockIterParam &iter_param) { int ret = OB_SUCCESS; @@ -646,7 +752,6 @@ int ObDDLMergeEmptyIterator::init(const ObMicroBlockData &idx_block_data, const ObStorageDatumUtils *datum_utils, ObIAllocator *allocator, const bool is_reverse_scan, - const bool set_iter_end, const ObIndexBlockIterParam &iter_param) { is_inited_ = true; @@ -870,7 +975,6 @@ int ObDDLMergeBlockRowIterator::init(const ObMicroBlockData &idx_block_data, const ObStorageDatumUtils *datum_utils, ObIAllocator *allocator, const bool is_reverse_scan, - const bool set_iter_end, const ObIndexBlockIterParam &iter_param) { int ret = OB_SUCCESS; @@ -888,7 +992,6 @@ int ObDDLMergeBlockRowIterator::init(const ObMicroBlockData &idx_block_data, datum_utils, allocator, is_reverse_scan, - set_iter_end, iter_param, sst_index_iter))) { LOG_WARN("fail to init sstable index iter", K(ret), K(iters_), KPC(sst_index_iter)); @@ -970,7 +1073,6 @@ int ObDDLMergeBlockRowIterator::init_sstable_index_iter(const ObMicroBlockData & const ObStorageDatumUtils *datum_utils, ObIAllocator *allocator, const bool is_reverse_scan, - const bool set_iter_end, const ObIndexBlockIterParam &iter_param, ObIndexBlockRowIterator *&sst_index_iter) { @@ -1064,7 +1166,7 @@ int ObDDLMergeBlockRowIterator::init_sstable_index_iter(const ObMicroBlockData & if (OB_ISNULL(sst_index_iter)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("iter is null", K(idx_block_data.type_), K(ret)); - } else if (OB_FAIL(sst_index_iter->init(idx_block_data, datum_utils, allocator, is_reverse_scan, set_iter_end, iter_param))) { + } else if (OB_FAIL(sst_index_iter->init(idx_block_data, datum_utils, allocator, is_reverse_scan, iter_param))) { LOG_WARN("fail to init iter", K(ret), K(idx_block_data), KPC(sst_index_iter)); } } @@ -2029,7 +2131,6 @@ int ObDDLMergeBlockRowIterator::get_index_row_count(const ObDatumRange &range, datum_utils_, allocator_, is_reverse_scan_, - false/*set iter end*/, iter_param_))) { LOG_WARN("fail to init iter", K(ret), KPC(idx_block_data_), KPC(tmp_merge_iter)); } else if (OB_FAIL(tmp_merge_iter->locate_range(range, is_left_border, is_right_border, true/*is_normal_cg*/))) { diff --git a/src/storage/blocksstable/index_block/ob_ddl_index_block_row_iterator.h b/src/storage/blocksstable/index_block/ob_ddl_index_block_row_iterator.h index b3e96064cf..767e752462 100644 --- a/src/storage/blocksstable/index_block/ob_ddl_index_block_row_iterator.h +++ b/src/storage/blocksstable/index_block/ob_ddl_index_block_row_iterator.h @@ -35,7 +35,6 @@ public: const ObStorageDatumUtils *datum_utils, ObIAllocator *allocator, const bool is_reverse_scan, - const bool set_iter_end, const ObIndexBlockIterParam &iter_param) override; virtual int get_current(const ObIndexBlockRowHeader *&idx_row_header, const ObDatumRowkey *&endkey) override; @@ -52,6 +51,9 @@ public: const bool is_left_border, const bool is_right_border, const bool is_normal_cg) override; + virtual int locate_range() override; + virtual int skip_to_next_valid_position(const ObDatumRowkey &rowkey) override; + virtual int find_rowkeys_belong_to_same_idx_row(ObMicroIndexInfo &idx_block_row, int64_t &rowkey_begin_idx, int64_t &rowkey_end_idx, const ObRowsInfo *&rows_info) override; virtual int check_blockscan(const ObDatumRowkey &rowkey, bool &can_blockscan) override; virtual bool end_of_block() const override; virtual int get_index_row_count(const ObDatumRange &range, @@ -60,6 +62,7 @@ public: int64_t &index_row_count) override; virtual void reset() override; virtual void reuse() override; + virtual void set_iter_end() override { is_iter_finish_ = true; } INHERIT_TO_STRING_KV("base iterator:", ObIndexBlockRowIterator, "format:", "ObDDLIndexBlockRowIterator", K_(is_iter_start), K_(is_iter_finish), KP(cur_tree_value_), KP(block_meta_tree_), K(is_normal_cg_)); public: @@ -69,7 +72,6 @@ public: const bool is_normal_cg, const int64_t iter_step = INT64_MAX); bool is_valid() { return OB_NOT_NULL(block_meta_tree_); } - void set_iter_end() { is_iter_finish_ = true; } int get_next_meta(const ObDataMacroBlockMeta *&meta); private: bool is_iter_start_; @@ -90,7 +92,6 @@ public: const ObStorageDatumUtils *datum_utils, ObIAllocator *allocator, const bool is_reverse_scan, - const bool set_iter_end, const ObIndexBlockIterParam &iter_param) override; virtual int get_current(const ObIndexBlockRowHeader *&idx_row_header, const ObDatumRowkey *&endkey) override; @@ -139,7 +140,6 @@ public: const ObStorageDatumUtils *datum_utils, ObIAllocator *allocator, const bool is_reverse_scan, - const bool set_iter_end, const ObIndexBlockIterParam &iter_param) override; virtual int get_current(const ObIndexBlockRowHeader *&idx_row_header, const ObDatumRowkey *&endkey) override; @@ -178,7 +178,6 @@ public: const ObStorageDatumUtils *datum_utils, ObIAllocator *allocator, const bool is_reverse_scan, - const bool set_iter_end, const ObIndexBlockIterParam &iter_param) override; virtual int get_current(const ObIndexBlockRowHeader *&idx_row_header, const ObDatumRowkey *&endkey) override; @@ -254,7 +253,6 @@ private: const ObStorageDatumUtils *datum_utils, ObIAllocator *allocator, const bool is_reverse_scan, - const bool set_iter_end, const ObIndexBlockIterParam &iter_param, ObIndexBlockRowIterator *&sst_index_iter); int init_ddl_kv_index_iters(const ObMicroBlockData &idx_block_data, diff --git a/src/storage/blocksstable/index_block/ob_index_block_row_scanner.cpp b/src/storage/blocksstable/index_block/ob_index_block_row_scanner.cpp index c090e630ad..8ea5d01780 100644 --- a/src/storage/blocksstable/index_block/ob_index_block_row_scanner.cpp +++ b/src/storage/blocksstable/index_block/ob_index_block_row_scanner.cpp @@ -410,7 +410,6 @@ int ObRAWIndexBlockRowIterator::init(const ObMicroBlockData &idx_block_data, const ObStorageDatumUtils *datum_utils, ObIAllocator *allocator, const bool is_reverse_scan, - const bool set_iter_end, const ObIndexBlockIterParam &iter_param) { int ret = OB_SUCCESS; @@ -502,6 +501,93 @@ int ObRAWIndexBlockRowIterator::locate_range(const ObDatumRange &range, return ret; } +int ObRAWIndexBlockRowIterator::locate_range() +{ + int ret = OB_SUCCESS; + int64_t row_count = 0; + if (IS_NOT_INIT) { + ret = OB_NOT_INIT; + LOG_WARN("Iter not opened yet", K(ret), KPC(this)); + } else if (OB_FAIL(micro_reader_->get_row_count(row_count))) { + LOG_WARN("Failed to get row count", K(ret), K(micro_reader_)); + } else { + start_ = 0; + end_ = row_count - 1; + current_ = 0; + } + return ret; +} + +int ObRAWIndexBlockRowIterator::skip_to_next_valid_position(const ObDatumRowkey &rowkey) +{ + int ret = OB_SUCCESS; + bool equal = false; + if (IS_NOT_INIT) { + ret = OB_NOT_INIT; + LOG_WARN("Iter not opened yet", K(ret), KPC(this)); + } else if (OB_FAIL(micro_reader_->find_bound(rowkey, true, current_, current_, equal))) { + LOG_WARN("Failed to skip to next valid position in micro block reader", K(ret), K(current_), K(rowkey)); + } else if (current_ == (end_ + 1)) { + ret = OB_ITER_END; + } + return ret; +} + +int ObRAWIndexBlockRowIterator::find_rowkeys_belong_to_same_idx_row(ObMicroIndexInfo &idx_block_row, int64_t &rowkey_begin_idx, int64_t &rowkey_end_idx, const ObRowsInfo *&rows_info) +{ + int ret = OB_SUCCESS; + if (IS_NOT_INIT) { + ret = OB_NOT_INIT; + LOG_WARN("Iter not opened yet", K(ret), KPC(this)); + } else if (OB_ISNULL(rows_info)) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid rows info", K(ret)); + } else { + bool is_decided = false; + for (; OB_SUCC(ret) && rowkey_begin_idx < rowkey_end_idx; ++rowkey_begin_idx) { + if (rows_info->is_row_skipped(rowkey_begin_idx)) { + continue; + } + const ObDatumRowkey &rowkey = rows_info->get_rowkey(rowkey_begin_idx); + int32_t cmp_ret = 0; + if (OB_FAIL(compare_rowkey(rowkey, cmp_ret))) { + LOG_WARN("fail to cmp rowkey in iter", K(ret), K(*this), K(rowkey)); + } else { + cmp_ret = -cmp_ret; + } + + if (OB_FAIL(ret)) { + } else if (cmp_ret > 0) { + idx_block_row.rowkey_end_idx_ = rowkey_begin_idx; + is_decided = true; + break; + } else if (cmp_ret == 0) { + idx_block_row.rowkey_end_idx_ = rowkey_begin_idx + 1; + is_decided = true; + break; + } + } + + if (OB_SUCC(ret) && !is_decided) { + idx_block_row.rowkey_end_idx_ = rowkey_begin_idx; + } + } + return ret; +} + +int ObRAWIndexBlockRowIterator::compare_rowkey(const ObDatumRowkey &rowkey, int32_t &cmp_ret) +{ + int ret = OB_SUCCESS; + cmp_ret = 0; + if (IS_NOT_INIT) { + ret = OB_NOT_INIT; + LOG_WARN("Iter not opened yet", K(ret), KPC(this)); + } else if (OB_FAIL(micro_reader_->compare_rowkey(rowkey, current_, cmp_ret))) { + LOG_WARN("Failed to compare rowkey", K(ret), K(rowkey)); + } + return ret; +} + int ObRAWIndexBlockRowIterator::check_blockscan(const ObDatumRowkey &rowkey, bool &can_blockscan) { int ret = OB_SUCCESS; @@ -709,7 +795,6 @@ int ObTFMIndexBlockRowIterator::init(const ObMicroBlockData &idx_block_data, const ObStorageDatumUtils *datum_utils, ObIAllocator *allocator, const bool is_reverse_scan, - const bool set_iter_end, const ObIndexBlockIterParam &iter_param) { int ret = OB_SUCCESS; @@ -726,11 +811,6 @@ int ObTFMIndexBlockRowIterator::init(const ObMicroBlockData &idx_block_data, is_reverse_scan_ = is_reverse_scan; iter_step_ = is_reverse_scan_ ? -1 : 1; datum_utils_ = datum_utils; - if (set_iter_end) { - current_ = 0; - start_ = 0; - end_ = idx_data_header_->row_cnt_ - 1; - } is_inited_ = true; } return ret; @@ -857,6 +937,19 @@ int ObTFMIndexBlockRowIterator::locate_range(const ObDatumRange &range, return ret; } +int ObTFMIndexBlockRowIterator::locate_range() +{ + int ret = OB_SUCCESS; + if (IS_NOT_INIT) { + ret = OB_NOT_INIT; + LOG_WARN("Iter not opened yet", K(ret), KPC(this)); + } else { + start_ = 0; + end_ = idx_data_header_->row_cnt_ - 1; + current_ = 0; + } + return ret; +} int ObTFMIndexBlockRowIterator::check_blockscan(const ObDatumRowkey &rowkey, bool &can_blockscan) { @@ -1134,79 +1227,67 @@ int ObTFMIndexBlockRowIterator::get_cur_row_id_range(const ObCSRange &parent_row return ret; } -int ObTFMIndexBlockRowIterator::skip_to_next_valid_position(ObMicroIndexInfo &idx_block_row, - int64_t &rowkey_begin_idx, - int64_t &rowkey_end_idx, - const ObRowsInfo *&rows_info) +int ObTFMIndexBlockRowIterator::skip_to_next_valid_position(const ObDatumRowkey &rowkey) { int ret = OB_SUCCESS; if (IS_NOT_INIT) { ret = OB_NOT_INIT; LOG_WARN("Iter not opened yet", K(ret), KPC(this)); } else { - for (; rowkey_begin_idx < rowkey_end_idx; ++rowkey_begin_idx) { - if (!rows_info->is_row_skipped(rowkey_begin_idx)) { - break; - } - } - - if (rowkey_begin_idx == rowkey_end_idx) { + ObDatumComparor cmp(*datum_utils_, ret, false, true, false); + const ObDatumRowkey *first = idx_data_header_->rowkey_array_ + current_; + const ObDatumRowkey *last = idx_data_header_->rowkey_array_ + end_ + 1; + const ObDatumRowkey *found = std::lower_bound(first, last, rowkey, cmp); + if (OB_FAIL(ret)) { + LOG_WARN("Failed to get lower bound of rowkey", K(ret), K(rowkey), KPC_(idx_data_header)); + } else if (found == last) { ret = OB_ITER_END; } else { - const ObDatumRowkey &rowkey = rows_info->get_rowkey(rowkey_begin_idx); - ObDatumComparor cmp(*datum_utils_, ret); - const ObDatumRowkey *first = idx_data_header_->rowkey_array_ + current_; - const ObDatumRowkey *last = idx_data_header_->rowkey_array_ + end_ + 1; - const ObDatumRowkey *found = std::lower_bound(first, last, rowkey, cmp); - if (OB_FAIL(ret)) { - LOG_WARN("Failed to get lower bound of rowkey", K(ret), K(rowkey), KPC(this)); - } else if (found == last) { - ret = OB_ITER_END; - } else { - current_= found - idx_data_header_->rowkey_array_; - idx_block_row.rows_info_ = rows_info; - idx_block_row.rowkey_begin_idx_ = rowkey_begin_idx++; - if (OB_FAIL(find_rowkeys_belong_to_same_idx_row(idx_block_row.rowkey_end_idx_, rowkey_begin_idx, rowkey_end_idx, rows_info))) { - LOG_WARN("Failed to find rowkeys belong to same index row", K(ret), K(rowkey_begin_idx), K(rowkey_end_idx), KPC(rows_info)); - } - } + current_ = found - idx_data_header_->rowkey_array_; } } return ret; } -int ObTFMIndexBlockRowIterator::find_rowkeys_belong_to_same_idx_row(int64_t &rowkey_idx, - int64_t &rowkey_begin_idx, - int64_t &rowkey_end_idx, - const ObRowsInfo *&rows_info) +int ObTFMIndexBlockRowIterator::find_rowkeys_belong_to_same_idx_row(ObMicroIndexInfo &idx_block_row, int64_t &rowkey_begin_idx, int64_t &rowkey_end_idx, const ObRowsInfo *&rows_info) { int ret = OB_SUCCESS; - const ObDatumRowkey *cur_rowkey = idx_data_header_->rowkey_array_ + current_; - bool is_decided = false; if (IS_NOT_INIT) { ret = OB_NOT_INIT; LOG_WARN("Iter not opened yet", K(ret), KPC(this)); + } else if (OB_ISNULL(rows_info)) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid rows info", K(ret)); } else { + const ObDatumRowkey *cur_rowkey = idx_data_header_->rowkey_array_ + current_; + bool is_decided = false; for (; OB_SUCC(ret) && rowkey_begin_idx < rowkey_end_idx; ++rowkey_begin_idx) { if (rows_info->is_row_skipped(rowkey_begin_idx)) { continue; } const ObDatumRowkey &rowkey = rows_info->get_rowkey(rowkey_begin_idx); - int cmp_ret = 0; - if (OB_FAIL(rowkey.compare(*cur_rowkey, *datum_utils_, cmp_ret))) { + int32_t cmp_ret = 0; + if (OB_ISNULL(cur_rowkey)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("null rowkey", K(ret), K(current_), KP(cur_rowkey)); + } else if (OB_FAIL(rowkey.compare(*cur_rowkey, *datum_utils_, cmp_ret, false))) { LOG_WARN("Failed to compare rowkey", K(ret), K(rowkey), KPC(cur_rowkey)); + } + + if (OB_FAIL(ret)) { } else if (cmp_ret > 0) { - rowkey_idx = rowkey_begin_idx; + idx_block_row.rowkey_end_idx_ = rowkey_begin_idx; is_decided = true; break; } else if (cmp_ret == 0) { - rowkey_idx = rowkey_begin_idx + 1; + idx_block_row.rowkey_end_idx_ = rowkey_begin_idx + 1; is_decided = true; break; } } - if (!is_decided) { - rowkey_idx = rowkey_begin_idx; + + if (OB_SUCC(ret) && !is_decided) { + idx_block_row.rowkey_end_idx_ = rowkey_begin_idx; } } return ret; @@ -1350,7 +1431,7 @@ int ObIndexBlockRowScanner::open( ret = OB_INVALID_ARGUMENT; LOG_WARN("Invalid argument to open an index micro block", K(ret), K(macro_id), K(idx_block_data), K(rowkey), K_(is_normal_cg), KP(idx_info)); - } else if (OB_FAIL(init_by_micro_data(idx_block_data, false/*set iter finish*/))) { + } else if (OB_FAIL(init_by_micro_data(idx_block_data))) { LOG_WARN("Fail to init scanner by micro data", K(ret), K(idx_block_data), K(index_format_)); } else if (OB_ISNULL(iter_)) { ret = OB_ERR_UNEXPECTED; @@ -1404,11 +1485,13 @@ int ObIndexBlockRowScanner::open( ret = OB_INVALID_ARGUMENT; LOG_WARN("Invalid argument to open an index micro block", K(ret), K(macro_id), K(idx_block_data), KP(rows_info)); - } else if (OB_FAIL(init_by_micro_data(idx_block_data, true/*set iter finish*/))) { + } else if (OB_FAIL(init_by_micro_data(idx_block_data))) { LOG_WARN("Fail to init scanner by micro data", K(ret), K(idx_block_data)); - } else if (OB_ISNULL(iter_) || ObIndexFormat::TRANSFORMED != index_format_) { + } else if (OB_ISNULL(iter_)) { ret = OB_ERR_UNEXPECTED; - LOG_WARN("Unexpected index format or iter is null", K(index_format_), K(ret), KPC(iter_)); + LOG_WARN("iter is null", K(index_format_), K(ret), KPC(iter_)); + } else if (OB_FAIL(iter_->locate_range())) { + LOG_WARN("fail to locate range", K(ret), KPC(iter_)); } else { macro_id_ = macro_id; rows_info_ = rows_info; @@ -1436,7 +1519,7 @@ int ObIndexBlockRowScanner::open( || !idx_block_data.is_index_block() || (is_normal_cg_ && nullptr == idx_info))) { ret = OB_INVALID_ARGUMENT; LOG_WARN("Invalid argument to open an index micro block", K(ret), K(idx_block_data), K(range), K_(is_normal_cg), KP(idx_info)); - } else if (OB_FAIL(init_by_micro_data(idx_block_data, false/*set iter finish*/))) { + } else if (OB_FAIL(init_by_micro_data(idx_block_data))) { LOG_WARN("Fail to init scanner by micro data", K(ret), K(idx_block_data)); } else if (OB_ISNULL(iter_)) { ret = OB_ERR_UNEXPECTED; @@ -1472,14 +1555,14 @@ int ObIndexBlockRowScanner::get_next( LOG_WARN("Not inited", K(ret)); } else if (end_of_block()) { ret = OB_ITER_END; - } else if (is_multi_check && OB_FAIL(iter_->skip_to_next_valid_position(idx_block_row, rowkey_begin_idx_, rowkey_end_idx_, rows_info_))) { + } else if (is_multi_check && OB_FAIL(skip_to_next_valid_position(idx_block_row))) { if (OB_UNLIKELY(OB_ITER_END != ret)) { LOG_WARN("Failed to skip to next valid position", K(ret), K(rowkey_begin_idx_), K(rowkey_end_idx_), KPC(rows_info_)); } else if (OB_ISNULL(iter_)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("iter is null", K(index_format_), K(ret)); } else { - iter_->reuse(); + iter_->set_iter_end(); } } else if (OB_FAIL(get_next_idx_row(idx_block_row))) { LOG_WARN("Failed to get next idx row", K(ret), K(is_multi_check)); @@ -1563,7 +1646,7 @@ int ObIndexBlockRowScanner::check_blockscan( return ret; } -int ObIndexBlockRowScanner::init_by_micro_data(const ObMicroBlockData &idx_block_data, bool set_iter_end) +int ObIndexBlockRowScanner::init_by_micro_data(const ObMicroBlockData &idx_block_data) { int ret = OB_SUCCESS; void *iter_buf = nullptr; @@ -1632,7 +1715,7 @@ int ObIndexBlockRowScanner::init_by_micro_data(const ObMicroBlockData &idx_block if (OB_ISNULL(iter_)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("iter is null", K(index_format_), K(ret)); - } else if (OB_FAIL(iter_->init(idx_block_data, datum_utils_, allocator_, is_reverse_scan_, set_iter_end, iter_param_))) { + } else if (OB_FAIL(iter_->init(idx_block_data, datum_utils_, allocator_, is_reverse_scan_, iter_param_))) { LOG_WARN("fail to init iter", K(ret), K(idx_block_data), KPC(iter_)); } } @@ -1817,5 +1900,31 @@ void ObIndexBlockRowScanner::skip_index_rows() } } +int ObIndexBlockRowScanner::skip_to_next_valid_position(ObMicroIndexInfo &idx_block_row) +{ + int ret = OB_SUCCESS; + skip_index_rows(); + if (IS_NOT_INIT) { + ret = OB_NOT_INIT; + LOG_WARN("Not inited", K(ret)); + } else if (rowkey_begin_idx_ == rowkey_end_idx_) { + ret = OB_ITER_END; + } else if (OB_ISNULL(iter_)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("iter is null", K(index_format_), K(ret)); + } else if (OB_FAIL(iter_->skip_to_next_valid_position(rows_info_->get_rowkey(rowkey_begin_idx_)))) { + if (OB_ITER_END != ret) { + LOG_WARN("fail to skip to next valid position", K(ret), K(rowkey_begin_idx_), K(rowkey_end_idx_), KPC(rows_info_), KPC(iter_)); + } + } else { + idx_block_row.rows_info_ = rows_info_; + idx_block_row.rowkey_begin_idx_ = rowkey_begin_idx_; + if (OB_FAIL(iter_->find_rowkeys_belong_to_same_idx_row(idx_block_row, rowkey_begin_idx_, rowkey_end_idx_, rows_info_))) { + LOG_WARN("Failed to find rowkeys belong to same index row", K(ret), KPC(iter_)); + } + } + return ret; +} + } // namespace blocksstable } // namespace oceanbase diff --git a/src/storage/blocksstable/index_block/ob_index_block_row_scanner.h b/src/storage/blocksstable/index_block/ob_index_block_row_scanner.h index cb6e0bbcdf..5de1b3b406 100644 --- a/src/storage/blocksstable/index_block/ob_index_block_row_scanner.h +++ b/src/storage/blocksstable/index_block/ob_index_block_row_scanner.h @@ -138,7 +138,6 @@ public: const ObStorageDatumUtils *datum_utils, ObIAllocator *allocator, const bool is_reverse_scan, - const bool set_iter_end, const ObIndexBlockIterParam &iter_param) = 0; virtual int get_current(const ObIndexBlockRowHeader *&idx_row_header, const ObDatumRowkey *&endkey) = 0; @@ -155,6 +154,7 @@ public: const bool is_left_border, const bool is_right_border, const bool is_normal_cg) = 0; + virtual int locate_range() { return OB_NOT_SUPPORTED; } virtual int check_blockscan(const ObDatumRowkey &rowkey, bool &can_blockscan) = 0; virtual bool end_of_block() const = 0; virtual int get_index_row_count(const ObDatumRange &range, @@ -173,16 +173,15 @@ public: const ObCSRange &parent_row_range, bool &is_certain, int64_t &found_idx) { return OB_NOT_SUPPORTED; } - virtual int skip_to_next_valid_position(ObMicroIndexInfo &idx_block_row, - int64_t &rowkey_begin_idx, - int64_t &rowkey_end_idx, - const ObRowsInfo *&rows_info) { return OB_NOT_SUPPORTED; } + virtual int skip_to_next_valid_position(const ObDatumRowkey &rowkey) { return OB_NOT_SUPPORTED; } + virtual int find_rowkeys_belong_to_same_idx_row(ObMicroIndexInfo &idx_block_row, int64_t &rowkey_begin_idx, int64_t &rowkey_end_idx, const ObRowsInfo *&rows_info) { return OB_NOT_SUPPORTED; } virtual int advance_to_border(const ObDatumRowkey &rowkey, const bool is_left_border, const bool is_right_border, const ObCSRange &parent_row_range, ObCSRange &cs_range) { return OB_NOT_SUPPORTED; } virtual void get_end_key(const ObDatumRowkey *&rowkey) {} + virtual void set_iter_end() {} public: virtual int switch_context(ObStorageDatumUtils *datum_utils) { @@ -210,7 +209,6 @@ public: const ObStorageDatumUtils *datum_utils, ObIAllocator *allocator, const bool is_reverse_scan, - const bool set_iter_end, const ObIndexBlockIterParam &iter_param) override; virtual int get_current(const ObIndexBlockRowHeader *&idx_row_header, const ObDatumRowkey *&endkey) override; @@ -227,6 +225,10 @@ public: const bool is_left_border, const bool is_right_border, const bool is_normal_cg) override; + virtual int locate_range() override; + virtual int skip_to_next_valid_position(const ObDatumRowkey &rowkey) override; + virtual int find_rowkeys_belong_to_same_idx_row(ObMicroIndexInfo &idx_block_row, int64_t &rowkey_begin_idx, int64_t &rowkey_end_idx, const ObRowsInfo *&rows_info) override; + virtual void set_iter_end() override { current_ = ObIMicroBlockReader::INVALID_ROW_INDEX; } virtual int check_blockscan(const ObDatumRowkey &rowkey, bool &can_blockscan) override; virtual bool end_of_block() const override; virtual int get_index_row_count(const ObDatumRange &range, @@ -240,6 +242,7 @@ public: private: int init_datum_row(const ObStorageDatumUtils &datum_utils, ObIAllocator *allocator); bool is_in_border(bool is_reverse_scan, bool is_left_border, bool is_right_border); + int compare_rowkey(const ObDatumRowkey &rowkey, int32_t &cmp_ret); protected: int64_t current_; int64_t start_; // inclusive @@ -260,7 +263,6 @@ public: const ObStorageDatumUtils *datum_utils, ObIAllocator *allocator, const bool is_reverse_scan, - const bool set_iter_end, const ObIndexBlockIterParam &iter_param) override; virtual int get_current(const ObIndexBlockRowHeader *&idx_row_header, const ObDatumRowkey *&endkey) override; @@ -277,6 +279,7 @@ public: const bool is_left_border, const bool is_right_border, const bool is_normal_cg) override; + virtual int locate_range() override; virtual int check_blockscan(const ObDatumRowkey &rowkey, bool &can_blockscan) override; virtual void reset() override; virtual void reuse() override; @@ -289,10 +292,8 @@ public: const ObCSRange &parent_row_range, bool &is_certain, int64_t &found_idx) override; - virtual int skip_to_next_valid_position(ObMicroIndexInfo &idx_block_row, - int64_t &rowkey_begin_idx, - int64_t &rowkey_end_idx, - const ObRowsInfo *&rows_info) override; + virtual int skip_to_next_valid_position(const ObDatumRowkey &rowkey) override; + virtual int find_rowkeys_belong_to_same_idx_row(ObMicroIndexInfo &idx_block_row, int64_t &rowkey_begin_idx, int64_t &rowkey_end_idx, const ObRowsInfo *&rows_info) override; virtual int get_idx_row_header_in_target_idx(const int64_t idx, const ObIndexBlockRowHeader *&idx_row_header) override; virtual int advance_to_border(const ObDatumRowkey &rowkey, @@ -306,10 +307,6 @@ public: private: int get_cur_row_id_range(const ObCSRange &parent_row_range, ObCSRange &cs_range); - int find_rowkeys_belong_to_same_idx_row(int64_t &rowkey_idx, - int64_t &rowkey_begin_idx, - int64_t &rowkey_end_idx, - const ObRowsInfo *&rows_info); private: const ObIndexBlockDataHeader *idx_data_header_; @@ -391,7 +388,7 @@ public: K_(is_normal_cg), K_(parent_row_range), K_(filter_constant_type), K_(is_normal_query), K_(iter_param)); private: - int init_by_micro_data(const ObMicroBlockData &idx_block_data, bool set_iter_end); + int init_by_micro_data(const ObMicroBlockData &idx_block_data); int locate_key(const ObDatumRowkey &rowkey); int init_datum_row(); int read_curr_idx_row(const ObIndexBlockRowHeader *&idx_row_header, const ObDatumRowkey *&endkey); @@ -405,6 +402,7 @@ private: ObCSRange &cs_range); int get_next_idx_row(ObMicroIndexInfo &idx_block_row); void skip_index_rows(); + int skip_to_next_valid_position(ObMicroIndexInfo &idx_block_row); private: union { const ObDatumRowkey *rowkey_; diff --git a/src/storage/blocksstable/ob_imicro_block_reader.h b/src/storage/blocksstable/ob_imicro_block_reader.h index 65df2acbae..cd084a6fd2 100644 --- a/src/storage/blocksstable/ob_imicro_block_reader.h +++ b/src/storage/blocksstable/ob_imicro_block_reader.h @@ -381,6 +381,10 @@ public: const int64_t begin_idx, int64_t &row_idx, bool &equal) = 0; + virtual int compare_rowkey( + const ObDatumRowkey &rowkey, + const int64_t index, + int32_t &compare_result) = 0; static int filter_white_filter( const sql::ObWhiteFilterExecutor &filter, const common::ObObjMeta &obj_meta, diff --git a/src/storage/blocksstable/ob_micro_block_reader.cpp b/src/storage/blocksstable/ob_micro_block_reader.cpp index 7b754c6f37..9fda19cd30 100644 --- a/src/storage/blocksstable/ob_micro_block_reader.cpp +++ b/src/storage/blocksstable/ob_micro_block_reader.cpp @@ -441,6 +441,27 @@ int ObMicroBlockReader::init( return ret; } +int ObMicroBlockReader::compare_rowkey( + const ObDatumRowkey &rowkey, + const int64_t idx, + int32_t &compare_result) +{ + int ret = OB_SUCCESS; + if (IS_NOT_INIT) { + ret = OB_NOT_INIT; + LOG_WARN("Not inited", K(ret)); + } else if (OB_UNLIKELY(!rowkey.is_valid() || idx < 0 || idx >= row_count_)) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("Invalid argument", K(ret), K(rowkey), K(idx), K_(row_count)); + } else if (OB_FAIL(flat_row_reader_.compare_meta_rowkey(rowkey, + *datum_utils_, + data_begin_ + index_data_[idx], + index_data_[idx + 1] - index_data_[idx], + compare_result))) { + LOG_WARN("Failed to compare rowkey", K(ret), K(rowkey), K_(row_count), K(idx)); + } + return ret; +} int ObMicroBlockReader::find_bound( const ObDatumRowkey &key, diff --git a/src/storage/blocksstable/ob_micro_block_reader.h b/src/storage/blocksstable/ob_micro_block_reader.h index eac2f9b1a4..84f545178e 100644 --- a/src/storage/blocksstable/ob_micro_block_reader.h +++ b/src/storage/blocksstable/ob_micro_block_reader.h @@ -134,6 +134,10 @@ public: const int32_t col_offset, const int64_t row_index, ObStorageDatum &datum) override; + virtual int compare_rowkey( + const ObDatumRowkey &rowkey, + const int64_t index, + int32_t &compare_result) override; virtual int find_bound( const ObDatumRowkey &key, const bool lower_bound, diff --git a/src/storage/ddl/ob_tablet_ddl_kv.cpp b/src/storage/ddl/ob_tablet_ddl_kv.cpp index 678f2a5db0..b36bd69885 100644 --- a/src/storage/ddl/ob_tablet_ddl_kv.cpp +++ b/src/storage/ddl/ob_tablet_ddl_kv.cpp @@ -673,6 +673,42 @@ int ObBlockMetaTree::locate_range(const blocksstable::ObDatumRange &range, return ret; } +int ObBlockMetaTree::skip_to_next_valid_position(const blocksstable::ObDatumRowkey &rowkey, + const blocksstable::ObStorageDatumUtils &datum_utils, + blocksstable::DDLBtreeIterator &iter, + ObBlockMetaTreeValue *&tree_value) const +{ + int ret = OB_SUCCESS; + tree_value = nullptr; + if (OB_UNLIKELY(!is_inited_)) { + ret = OB_NOT_INIT; + LOG_WARN("not init", K(ret)); + } else { + int cmp_ret = 0; + while (OB_SUCC(ret)) { + ObDatumRowkeyWrapper rowkey_wrapper; + ObBlockMetaTreeValue *tmp_tree_value = nullptr; + if (OB_FAIL(iter.get_next(rowkey_wrapper, tmp_tree_value))) { + if (OB_ITER_END != ret) { + LOG_WARN("get next failed", K(ret)); + } + // just return ITER_END + } else if (OB_FAIL(rowkey_wrapper.rowkey_->compare(rowkey, datum_utils, cmp_ret, false/*need_compare_datum_cnt*/))) { + LOG_WARN("fail to cmp rowkey", K(ret), K(rowkey), K(rowkey_wrapper)); + } else if(cmp_ret >= 0) { //lower bound + if (OB_ISNULL(tmp_tree_value)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("tree_value is null", K(ret), KP(tmp_tree_value)); + } else { + tree_value = tmp_tree_value; + } + break; + } + } + } + return ret; +} + int ObBlockMetaTree::get_next_tree_value(blocksstable::DDLBtreeIterator &iter, const int64_t step, ObBlockMetaTreeValue *&tree_value) const diff --git a/src/storage/ddl/ob_tablet_ddl_kv.h b/src/storage/ddl/ob_tablet_ddl_kv.h index c1e9401f04..58175dcd51 100644 --- a/src/storage/ddl/ob_tablet_ddl_kv.h +++ b/src/storage/ddl/ob_tablet_ddl_kv.h @@ -89,6 +89,10 @@ public: const bool is_reverse_scan, blocksstable::DDLBtreeIterator &iter, ObBlockMetaTreeValue *&cur_tree_value) const; + int skip_to_next_valid_position(const blocksstable::ObDatumRowkey &rowkey, + const blocksstable::ObStorageDatumUtils &datum_utils, + blocksstable::DDLBtreeIterator &iter, + ObBlockMetaTreeValue *&tree_value) const; int get_next_tree_value(blocksstable::DDLBtreeIterator &iter, const int64_t step, ObBlockMetaTreeValue *&tree_value) const;