Opt compact row memory alloc
This commit is contained in:
		@ -54,15 +54,17 @@ int RowMeta::init(const ObExprPtrIArray &exprs,
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
  fix_data_off_ = extra_off_ + extra_size_;
 | 
					  fix_data_off_ = extra_off_ + extra_size_;
 | 
				
			||||||
  if (OB_SUCC(ret) && fixed_cnt_ > 0) {
 | 
					  if (OB_SUCC(ret) && fixed_cnt_ > 0) {
 | 
				
			||||||
    if (OB_ISNULL(allocator_)) {
 | 
					    ObDataBuffer local_alloc(buf_, MAX_LOCAL_BUF_LEN);
 | 
				
			||||||
 | 
					    ObIAllocator *alloc = use_local_allocator() ? &local_alloc : allocator_;
 | 
				
			||||||
 | 
					    if (OB_ISNULL(alloc)) {
 | 
				
			||||||
      ret = OB_ERR_UNEXPECTED;
 | 
					      ret = OB_ERR_UNEXPECTED;
 | 
				
			||||||
      LOG_WARN("allocator is null", K(ret), K(lbt()));
 | 
					      LOG_WARN("allocator is null", K(ret), K(lbt()));
 | 
				
			||||||
    } else if (OB_ISNULL(projector_ =
 | 
					    } else if (OB_ISNULL(projector_ =
 | 
				
			||||||
        static_cast<int32_t *>(allocator_->alloc(sizeof(int32_t) * col_cnt_)))) {
 | 
					        static_cast<int32_t *>(alloc->alloc(sizeof(int32_t) * col_cnt_)))) {
 | 
				
			||||||
      ret = OB_ALLOCATE_MEMORY_FAILED;
 | 
					      ret = OB_ALLOCATE_MEMORY_FAILED;
 | 
				
			||||||
      LOG_WARN("alloc projector failed", K(ret), K(col_cnt_));
 | 
					      LOG_WARN("alloc projector failed", K(ret), K(col_cnt_));
 | 
				
			||||||
    } else if (OB_ISNULL(fixed_offsets_ =
 | 
					    } else if (OB_ISNULL(fixed_offsets_ =
 | 
				
			||||||
        static_cast<int32_t *>(allocator_->alloc(sizeof(int32_t) * (fixed_cnt_ + 1))))) {
 | 
					        static_cast<int32_t *>(alloc->alloc(sizeof(int32_t) * (fixed_cnt_ + 1))))) {
 | 
				
			||||||
      ret = OB_ALLOCATE_MEMORY_FAILED;
 | 
					      ret = OB_ALLOCATE_MEMORY_FAILED;
 | 
				
			||||||
      LOG_WARN("alloc fixed_offsets_ failed", K(ret), K(col_cnt_));
 | 
					      LOG_WARN("alloc fixed_offsets_ failed", K(ret), K(col_cnt_));
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
@ -80,14 +82,7 @@ int RowMeta::init(const ObExprPtrIArray &exprs,
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (OB_FAIL(ret)) {
 | 
					    if (OB_FAIL(ret)) {
 | 
				
			||||||
      if (NULL != fixed_offsets_) {
 | 
					      reset();
 | 
				
			||||||
        allocator_->free(fixed_offsets_);
 | 
					 | 
				
			||||||
        fixed_offsets_ = NULL;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      if (NULL != projector_) {
 | 
					 | 
				
			||||||
        allocator_->free(projector_);
 | 
					 | 
				
			||||||
        projector_ = NULL;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (OB_SUCC(ret)) {
 | 
					  if (OB_SUCC(ret)) {
 | 
				
			||||||
@ -104,16 +99,16 @@ int RowMeta::init(const ObExprPtrIArray &exprs,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void RowMeta::reset()
 | 
					void RowMeta::reset()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  if (NULL != allocator_) {
 | 
					  if (!use_local_allocator() && NULL != allocator_) {
 | 
				
			||||||
    if (NULL != fixed_offsets_) {
 | 
					    if (NULL != fixed_offsets_) {
 | 
				
			||||||
      allocator_->free(fixed_offsets_);
 | 
					      allocator_->free(fixed_offsets_);
 | 
				
			||||||
      fixed_offsets_ = NULL;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (NULL != projector_) {
 | 
					    if (NULL != projector_) {
 | 
				
			||||||
      allocator_->free(projector_);
 | 
					      allocator_->free(projector_);
 | 
				
			||||||
      projector_ = NULL;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  fixed_offsets_ = NULL;
 | 
				
			||||||
 | 
					  projector_ = NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int32_t RowMeta::get_row_fixed_size(const int64_t col_cnt,
 | 
					int32_t RowMeta::get_row_fixed_size(const int64_t col_cnt,
 | 
				
			||||||
@ -235,15 +230,17 @@ OB_DEF_DESERIALIZE(RowMeta)
 | 
				
			|||||||
              var_data_off_);
 | 
					              var_data_off_);
 | 
				
			||||||
  projector_ = NULL;
 | 
					  projector_ = NULL;
 | 
				
			||||||
  if (fixed_expr_reordered()) {
 | 
					  if (fixed_expr_reordered()) {
 | 
				
			||||||
    if (OB_ISNULL(allocator_)) {
 | 
					    ObDataBuffer local_alloc(buf_, MAX_LOCAL_BUF_LEN);
 | 
				
			||||||
 | 
					    ObIAllocator *alloc = use_local_allocator() ? &local_alloc : allocator_;
 | 
				
			||||||
 | 
					    if (OB_ISNULL(alloc)) {
 | 
				
			||||||
      ret = OB_ERR_UNEXPECTED;
 | 
					      ret = OB_ERR_UNEXPECTED;
 | 
				
			||||||
      LOG_WARN("allocator is null", K(ret));
 | 
					      LOG_WARN("allocator is null", K(ret));
 | 
				
			||||||
    } else if (OB_ISNULL(projector_ =
 | 
					    } else if (OB_ISNULL(projector_ =
 | 
				
			||||||
        static_cast<int32_t *>(allocator_->alloc(sizeof(int32_t) * col_cnt_)))) {
 | 
					        static_cast<int32_t *>(alloc->alloc(sizeof(int32_t) * col_cnt_)))) {
 | 
				
			||||||
      ret = OB_ALLOCATE_MEMORY_FAILED;
 | 
					      ret = OB_ALLOCATE_MEMORY_FAILED;
 | 
				
			||||||
      LOG_WARN("alloc projector failed", K(ret), K(col_cnt_));
 | 
					      LOG_WARN("alloc projector failed", K(ret), K(col_cnt_));
 | 
				
			||||||
    } else if (OB_ISNULL(fixed_offsets_ =
 | 
					    } else if (OB_ISNULL(fixed_offsets_ =
 | 
				
			||||||
        static_cast<int32_t *>(allocator_->alloc(sizeof(int32_t) * (fixed_cnt_ + 1))))) {
 | 
					        static_cast<int32_t *>(alloc->alloc(sizeof(int32_t) * (fixed_cnt_ + 1))))) {
 | 
				
			||||||
      ret = OB_ALLOCATE_MEMORY_FAILED;
 | 
					      ret = OB_ALLOCATE_MEMORY_FAILED;
 | 
				
			||||||
      LOG_WARN("alloc projector failed", K(ret), K(col_cnt_));
 | 
					      LOG_WARN("alloc projector failed", K(ret), K(col_cnt_));
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
@ -255,12 +252,7 @@ OB_DEF_DESERIALIZE(RowMeta)
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (OB_FAIL(ret)) {
 | 
					    if (OB_FAIL(ret)) {
 | 
				
			||||||
      if (projector_ != NULL) {
 | 
					      reset();
 | 
				
			||||||
        allocator_->free(projector_);
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      if (fixed_offsets_ != NULL) {
 | 
					 | 
				
			||||||
        allocator_->free(fixed_offsets_);
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  return ret;
 | 
					  return ret;
 | 
				
			||||||
@ -298,15 +290,17 @@ int RowMeta::deep_copy(const RowMeta &other, common::ObIAllocator *allocator)
 | 
				
			|||||||
  projector_ = NULL;
 | 
					  projector_ = NULL;
 | 
				
			||||||
  allocator_ = allocator;
 | 
					  allocator_ = allocator;
 | 
				
			||||||
  if (fixed_expr_reordered()) {
 | 
					  if (fixed_expr_reordered()) {
 | 
				
			||||||
    if (OB_ISNULL(allocator_)) {
 | 
					    ObDataBuffer local_alloc(buf_, MAX_LOCAL_BUF_LEN);
 | 
				
			||||||
 | 
					    ObIAllocator *alloc = use_local_allocator() ? &local_alloc : allocator_;
 | 
				
			||||||
 | 
					    if (OB_ISNULL(alloc)) {
 | 
				
			||||||
      ret = OB_ERR_UNEXPECTED;
 | 
					      ret = OB_ERR_UNEXPECTED;
 | 
				
			||||||
      LOG_WARN("allocator is null", K(ret));
 | 
					      LOG_WARN("allocator is null", K(ret));
 | 
				
			||||||
    } else if (OB_ISNULL(projector_ =
 | 
					    } else if (OB_ISNULL(projector_ =
 | 
				
			||||||
        static_cast<int32_t *>(allocator_->alloc(sizeof(int32_t) * col_cnt_)))) {
 | 
					        static_cast<int32_t *>(alloc->alloc(sizeof(int32_t) * col_cnt_)))) {
 | 
				
			||||||
      ret = OB_ALLOCATE_MEMORY_FAILED;
 | 
					      ret = OB_ALLOCATE_MEMORY_FAILED;
 | 
				
			||||||
      LOG_WARN("alloc projector failed", K(ret), K(col_cnt_));
 | 
					      LOG_WARN("alloc projector failed", K(ret), K(col_cnt_));
 | 
				
			||||||
    } else if (OB_ISNULL(fixed_offsets_ =
 | 
					    } else if (OB_ISNULL(fixed_offsets_ =
 | 
				
			||||||
        static_cast<int32_t *>(allocator_->alloc(sizeof(int32_t) * (fixed_cnt_ + 1))))) {
 | 
					        static_cast<int32_t *>(alloc->alloc(sizeof(int32_t) * (fixed_cnt_ + 1))))) {
 | 
				
			||||||
      ret = OB_ALLOCATE_MEMORY_FAILED;
 | 
					      ret = OB_ALLOCATE_MEMORY_FAILED;
 | 
				
			||||||
      LOG_WARN("alloc projector failed", K(ret), K(col_cnt_));
 | 
					      LOG_WARN("alloc projector failed", K(ret), K(col_cnt_));
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
@ -314,12 +308,7 @@ int RowMeta::deep_copy(const RowMeta &other, common::ObIAllocator *allocator)
 | 
				
			|||||||
      MEMCPY(fixed_offsets_, other.fixed_offsets_, (fixed_cnt_ + 1) * sizeof(int32_t));
 | 
					      MEMCPY(fixed_offsets_, other.fixed_offsets_, (fixed_cnt_ + 1) * sizeof(int32_t));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (OB_FAIL(ret)) {
 | 
					    if (OB_FAIL(ret)) {
 | 
				
			||||||
      if (projector_ != NULL) {
 | 
					      reset();
 | 
				
			||||||
        allocator_->free(projector_);
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      if (fixed_offsets_ != NULL) {
 | 
					 | 
				
			||||||
        allocator_->free(fixed_offsets_);
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  return ret;
 | 
					  return ret;
 | 
				
			||||||
 | 
				
			|||||||
@ -46,6 +46,7 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
struct RowMeta {
 | 
					struct RowMeta {
 | 
				
			||||||
  OB_UNIS_VERSION_V(1);
 | 
					  OB_UNIS_VERSION_V(1);
 | 
				
			||||||
 | 
					  static const int64_t MAX_LOCAL_BUF_LEN = 128;
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
  RowMeta(common::ObIAllocator *allocator = nullptr) : allocator_(allocator), col_cnt_(0), extra_size_(0),
 | 
					  RowMeta(common::ObIAllocator *allocator = nullptr) : allocator_(allocator), col_cnt_(0), extra_size_(0),
 | 
				
			||||||
              fixed_cnt_(0), fixed_offsets_(NULL), projector_(NULL),
 | 
					              fixed_cnt_(0), fixed_offsets_(NULL), projector_(NULL),
 | 
				
			||||||
@ -93,6 +94,13 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  TO_STRING_KV(K_(col_cnt), K_(extra_size), K_(fixed_cnt), K_(nulls_off), K_(var_offsets_off),
 | 
					  TO_STRING_KV(K_(col_cnt), K_(extra_size), K_(fixed_cnt), K_(nulls_off), K_(var_offsets_off),
 | 
				
			||||||
               K_(extra_off), K_(fix_data_off), K_(var_data_off));
 | 
					               K_(extra_off), K_(fix_data_off), K_(var_data_off));
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
					  inline bool use_local_allocator() const
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    return fixed_cnt_ > 0 && ((col_cnt_ + fixed_cnt_ + 1) * sizeof(int32_t) <= MAX_LOCAL_BUF_LEN);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
					  char buf_[MAX_LOCAL_BUF_LEN];
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
  common::ObIAllocator *allocator_;
 | 
					  common::ObIAllocator *allocator_;
 | 
				
			||||||
  int32_t col_cnt_;
 | 
					  int32_t col_cnt_;
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user