ob_dml_param.h 6.9 KB
Newer Older
O
oceanbase-admin 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
/**
 * Copyright (c) 2021 OceanBase
 * OceanBase CE is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */

#ifndef OCEANBASE_STORAGE_OB_DML_PARAM_
#define OCEANBASE_STORAGE_OB_DML_PARAM_

#include "lib/container/ob_iarray.h"
#include "common/ob_common_types.h"
#include "share/ob_i_data_access_service.h"
#include "share/datum/ob_datum.h"

namespace oceanbase {
namespace sql {
class ObTableLocation;
class ObEvalCtx;
class ObEvalInfo;
using common::ObDatum;
}  // namespace sql
namespace share {
namespace schema {
class ObTableParam;
class ObTableDMLParam;
}  // namespace schema
}  // namespace share
namespace storage {
class ObIPartitionGroupGuard;

//
// Project storage output row to expression array, the core project logic is:
//
//   if (cells[projector.at(i)].is_nop()) {
//     nop_pos[nop_cnt++] = i;
//   } else {
//     exprs.at(i).locate_datum_for_write().from_obj(cells[projector.at(i)])
//   }
//
// We introduce ObRow2ExprsProjector for optimization:
// 1. Save datum pointer of expression, locate datum once for each expression.
// 2. Project number, string, integer (OBJ_DATUM_8BYTE_DATA) by groups, to reduce type detection.
class ObRow2ExprsProjector {
G
gm 已提交
50
public:
O
oceanbase-admin 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
  explicit ObRow2ExprsProjector(common::ObIAllocator& alloc)
      : other_idx_(0),
        has_virtual_(false),
        outputs_(common::OB_MALLOC_NORMAL_BLOCK_SIZE, common::ModulePageAllocator(alloc))
  {}
  ~ObRow2ExprsProjector()
  {
    destroy();
  }

  int init(const sql::ObExprPtrIArray& exprs, sql::ObEvalCtx& eval_ctx, const common::ObIArray<int32_t>& projector);

  int project(const sql::ObExprPtrIArray& exprs, const common::ObObj* cells, int16_t* nop_pos, int64_t& nop_cnt);

  void destroy()
  {
    outputs_.reset();
  }
  bool has_virtual() const
  {
    return has_virtual_;
  }

G
gm 已提交
74
private:
O
oceanbase-admin 已提交
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
  struct Item {
    int32_t obj_idx_;
    int32_t expr_idx_;
    sql::ObDatum* datum_;
    sql::ObEvalInfo* eval_info_;
    const char* data_;

    Item() = default;
    DECLARE_TO_STRING;
  };

  template <common::ObObjDatumMapType OBJ_DATUM_MAP_TYPE, bool NEED_RESET_PTR>
  struct MapConvert {
    int32_t start_;
    int32_t end_;

    const static common::ObObjDatumMapType map_type_ = OBJ_DATUM_MAP_TYPE;
    MapConvert() : start_(0), end_(0)
    {}

    OB_INLINE void project(const Item* items, const common::ObObj* cells, int16_t* nop_pos, int64_t& nop_cnt) const
    {
      // performance critical, no parameter validity check.
      for (int32_t i = start_; i < end_; i++) {
        const Item& item = items[i];
        const common::ObObj& cell = cells[item.obj_idx_];
        if (OB_UNLIKELY(cell.is_nop_value())) {
          nop_pos[nop_cnt++] = item.expr_idx_;
        } else if (OB_UNLIKELY(cell.is_null())) {
          item.datum_->set_null();
        } else {
          if (NEED_RESET_PTR) {
            if (OB_UNLIKELY(item.datum_->ptr_ != item.data_)) {
              item.datum_->ptr_ = item.data_;
            }
          }
          item.datum_->obj2datum<OBJ_DATUM_MAP_TYPE>(cell);
        }
      }
    }
  };

  MapConvert<common::OBJ_DATUM_NUMBER, true> num_;
  MapConvert<common::OBJ_DATUM_STRING, false> str_;
  MapConvert<common::OBJ_DATUM_8BYTE_DATA, true> int_;
  int32_t other_idx_;
  bool has_virtual_;  // has virtual column
  common::ObSEArray<Item, 4> outputs_;
};

class ObTableScanParam : public common::ObVTableScanParam {
G
gm 已提交
126
public:
O
oceanbase-admin 已提交
127 128 129 130
  ObTableScanParam()
      : common::ObVTableScanParam(),
        trans_desc_(NULL),
        table_param_(NULL),
J
jg0 已提交
131
        allocator_(&CURRENT_CONTEXT->get_arena_allocator()),
O
oceanbase-admin 已提交
132 133 134 135 136 137 138 139 140 141 142 143 144 145
        part_filter_(NULL),
        part_mgr_(NULL),
        column_orders_(nullptr),
        need_scn_(false),
        fuse_row_cache_hit_rate_(0),
        block_cache_hit_rate_(0),
        ref_table_id_(common::OB_INVALID_ID),
        partition_guard_(NULL),
        iterator_mementity_(nullptr)
  {}
  explicit ObTableScanParam(transaction::ObTransDesc& trans_desc)
      : common::ObVTableScanParam(),
        trans_desc_(&trans_desc),
        table_param_(NULL),
J
jg0 已提交
146
        allocator_(&CURRENT_CONTEXT->get_arena_allocator()),
O
oceanbase-admin 已提交
147 148 149 150 151 152 153 154 155 156 157 158 159
        part_filter_(NULL),
        part_mgr_(NULL),
        column_orders_(nullptr),
        need_scn_(false),
        fuse_row_cache_hit_rate_(0),
        block_cache_hit_rate_(0),
        ref_table_id_(common::OB_INVALID_ID),
        partition_guard_(NULL),
        iterator_mementity_(nullptr)
  {}
  virtual ~ObTableScanParam()
  {}

G
gm 已提交
160
public:
O
oceanbase-admin 已提交
161 162 163 164 165 166 167 168 169 170 171 172
  transaction::ObTransDesc* trans_desc_;  // transaction handle
  const share::schema::ObTableParam* table_param_;
  common::ObArenaAllocator* allocator_;
  common::SampleInfo sample_info_;
  const sql::ObTableLocation* part_filter_;
  common::ObPartMgr* part_mgr_;
  common::ObArray<common::ObOrderType>* column_orders_;
  bool need_scn_;
  int16_t fuse_row_cache_hit_rate_;
  int16_t block_cache_hit_rate_;
  uint64_t ref_table_id_;  // main table id
  ObIPartitionGroupGuard* partition_guard_;
J
jg0 已提交
173
  lib::MemoryContext iterator_mementity_;
O
oceanbase-admin 已提交
174 175 176 177 178 179 180 181 182
  OB_INLINE virtual bool is_valid() const
  {
    return (NULL != trans_desc_ && trans_desc_->is_valid_or_standalone_stmt() && ObVTableScanParam::is_valid());
  }
  OB_INLINE common::ObIArray<common::ObOrderType>* get_rowkey_column_orders() const
  {
    return column_orders_;
  }

G
gm 已提交
183
private:
O
oceanbase-admin 已提交
184 185
  virtual int init_rowkey_column_orders();
  // TO_STRING_KV(N_TRANS_DESC, trans_desc_);
G
gm 已提交
186
private:
O
oceanbase-admin 已提交
187 188 189 190 191 192 193 194 195 196 197 198
  DISALLOW_COPY_AND_ASSIGN(ObTableScanParam);
};

struct ObDMLBaseParam {
  ObDMLBaseParam()
      : timeout_(-1),
        schema_version_(-1),
        query_flag_(),
        sql_mode_(DEFAULT_OCEANBASE_MODE),
        tz_info_(NULL),
        table_param_(NULL),
        tenant_schema_version_(OB_INVALID_VERSION),
L
leslieyuchen 已提交
199 200
        is_total_quantity_log_(false),
        only_data_table_(false),
O
oceanbase-admin 已提交
201 202
        is_ignore_(false),
        prelock_(false),
L
leslieyuchen 已提交
203 204 205 206 207 208
        duplicated_rows_(0),
        dml_allocator_(nullptr)
  {
    query_flag_.read_latest_ = common::ObQueryFlag::OBSF_MASK_READ_LATEST;
  }
  ~ObDMLBaseParam()
O
oceanbase-admin 已提交
209 210 211 212 213 214
  {}

  int64_t timeout_;
  int64_t schema_version_;
  common::ObQueryFlag query_flag_;
  ObSQLMode sql_mode_;
L
leslieyuchen 已提交
215
  const common::ObTimeZoneInfo *tz_info_;
O
oceanbase-admin 已提交
216 217 218 219
  common::ObColumnExprArray virtual_columns_;
  common::ObExprCtx expr_ctx_;
  const share::schema::ObTableDMLParam* table_param_;
  int64_t tenant_schema_version_;
L
leslieyuchen 已提交
220 221
  bool is_total_quantity_log_;
  bool only_data_table_;
O
oceanbase-admin 已提交
222 223
  bool is_ignore_;
  bool prelock_;
L
leslieyuchen 已提交
224 225
  mutable int64_t duplicated_rows_;
  common::ObIAllocator *dml_allocator_;
O
oceanbase-admin 已提交
226 227 228 229
  bool is_valid() const
  {
    return (timeout_ > 0 && schema_version_ >= 0);
  }
L
leslieyuchen 已提交
230
  DECLARE_TO_STRING;
O
oceanbase-admin 已提交
231 232 233 234 235 236
};

}  // end namespace storage
}  // end namespace oceanbase

#endif  // OCEANBASE_STORAGE_OB_DML_PARAM_