[FEAT MERGE] implement mysql dblink and read consistency
Co-authored-by: xianyu-w <707512433@qq.com> Co-authored-by: sdc <njucssdc@gmail.com> Co-authored-by: seuwebber <webber_code@163.com>
This commit is contained in:
96
src/sql/engine/expr/ob_expr_current_scn.cpp
Normal file
96
src/sql/engine/expr/ob_expr_current_scn.cpp
Normal file
@ -0,0 +1,96 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define USING_LOG_PREFIX SQL_ENG
|
||||
#include "sql/engine/expr/ob_expr_current_scn.h"
|
||||
#include "lib/ob_name_def.h"
|
||||
#include "sql/session/ob_sql_session_info.h"
|
||||
#include "sql/engine/ob_physical_plan_ctx.h"
|
||||
#include "sql/engine/ob_exec_context.h"
|
||||
#include "src/sql/engine/expr/ob_expr_util.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
using namespace common;
|
||||
using namespace share;
|
||||
using namespace transaction;
|
||||
#include "src/storage/tx/ob_tx_api.h"
|
||||
namespace sql
|
||||
{
|
||||
ObExprCurrentScn::ObExprCurrentScn(ObIAllocator &alloc)
|
||||
: ObFuncExprOperator(alloc, T_FUN_SYS_CURRENT_SCN, N_CURRENT_SCN, 0, NOT_VALID_FOR_GENERATED_COL, NOT_ROW_DIMENSION)
|
||||
{
|
||||
}
|
||||
ObExprCurrentScn::~ObExprCurrentScn()
|
||||
{
|
||||
}
|
||||
|
||||
int ObExprCurrentScn::calc_result_type0(ObExprResType &type, ObExprTypeCtx &type_ctx) const
|
||||
{
|
||||
UNUSED(type_ctx);
|
||||
if (is_oracle_mode()) {
|
||||
const ObAccuracy &acc = ObAccuracy::DDL_DEFAULT_ACCURACY2[common::ORACLE_MODE][common::ObNumberType];
|
||||
type.set_number();
|
||||
type.set_scale(acc.get_scale());
|
||||
type.set_precision(acc.get_precision());
|
||||
} else {
|
||||
const ObAccuracy &acc = common::ObAccuracy::DDL_DEFAULT_ACCURACY[common::ObUInt64Type];
|
||||
type.set_uint64();
|
||||
type.set_scale(acc.get_scale());
|
||||
type.set_precision(acc.get_precision());
|
||||
type.set_result_flag(NOT_NULL_FLAG);
|
||||
}
|
||||
return OB_SUCCESS;
|
||||
}
|
||||
|
||||
int ObExprCurrentScn::eval_current_scn(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSQLSessionInfo *session = NULL;
|
||||
if (OB_ISNULL(session = ctx.exec_ctx_.get_my_session())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("session is null", K(ret));
|
||||
} else {
|
||||
share::SCN current_scn;
|
||||
ObTransService *txs = MTL(transaction::ObTransService*);
|
||||
int64_t query_timeout = 0;
|
||||
session->get_query_timeout(query_timeout);
|
||||
int64_t expire_ts = session->get_query_start_time() + query_timeout;
|
||||
if (OB_FAIL(txs->get_read_snapshot_version(expire_ts, current_scn))) {
|
||||
LOG_WARN("get read snapshot version", K(ret));
|
||||
} else if (ObUInt64Type == expr.datum_meta_.type_) {
|
||||
expr_datum.set_uint(current_scn.get_val_for_sql());
|
||||
} else {
|
||||
uint64_t scn_version = current_scn.get_val_for_sql();
|
||||
ObNumStackOnceAlloc tmp_alloc;
|
||||
number::ObNumber num;
|
||||
if (OB_FAIL(num.from(scn_version, tmp_alloc))) {
|
||||
LOG_WARN("copy number fail", K(ret));
|
||||
} else {
|
||||
expr_datum.set_number(num);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprCurrentScn::cg_expr(ObExprCGCtx &op_cg_ctx, const ObRawExpr &raw_expr,
|
||||
ObExpr &rt_expr) const
|
||||
{
|
||||
UNUSED(raw_expr);
|
||||
UNUSED(op_cg_ctx);
|
||||
rt_expr.eval_func_ = ObExprCurrentScn::eval_current_scn;
|
||||
return OB_SUCCESS;
|
||||
}
|
||||
|
||||
} //namespace sql
|
||||
} //namespace oceanbase
|
||||
40
src/sql/engine/expr/ob_expr_current_scn.h
Normal file
40
src/sql/engine/expr/ob_expr_current_scn.h
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* 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_SQL_OB_EXPR_CURRENT_SCN_H_
|
||||
#define OCEANBASE_SQL_OB_EXPR_CURRENT_SCN_H_
|
||||
|
||||
#include "sql/engine/expr/ob_expr_operator.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace sql
|
||||
{
|
||||
class ObExprCurrentScn : public ObFuncExprOperator
|
||||
{
|
||||
public:
|
||||
explicit ObExprCurrentScn(common::ObIAllocator &alloc);
|
||||
virtual ~ObExprCurrentScn();
|
||||
virtual int calc_result_type0(ObExprResType &type, common::ObExprTypeCtx &type_ctx) const;
|
||||
static int eval_current_scn(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum);
|
||||
virtual int cg_expr(ObExprCGCtx &op_cg_ctx,
|
||||
const ObRawExpr &raw_expr,
|
||||
ObExpr &rt_expr) const override;
|
||||
|
||||
private:
|
||||
// disallow copy
|
||||
DISALLOW_COPY_AND_ASSIGN(ObExprCurrentScn);
|
||||
};
|
||||
|
||||
} //sql
|
||||
} //oceanbase
|
||||
#endif //OCEANBASE_SQL_OB_EXPR_CURRENT_SCN_H_
|
||||
@ -310,6 +310,7 @@
|
||||
#include "ob_expr_encrypt.h"
|
||||
#include "ob_expr_coalesce.h"
|
||||
#include "ob_expr_cast.h"
|
||||
#include "ob_expr_current_scn.h"
|
||||
#include "ob_expr_icu_version.h"
|
||||
#include "ob_expr_sql_mode_convert.h"
|
||||
#include "ob_expr_priv_xml_binary.h"
|
||||
@ -1030,7 +1031,8 @@ static ObExpr::EvalFunc g_expr_eval_functions[] = {
|
||||
ObExprXmlcast::eval_xmlcast, /* 602 */
|
||||
ObExprUpdateXml::eval_update_xml, /* 603 */
|
||||
ObExprJoinFilter::eval_range_filter, /* 604 */
|
||||
ObExprJoinFilter::eval_in_filter /* 605 */
|
||||
ObExprJoinFilter::eval_in_filter, /* 605 */
|
||||
ObExprCurrentScn::eval_current_scn /* 606 */
|
||||
};
|
||||
|
||||
static ObExpr::EvalBatchFunc g_expr_eval_batch_functions[] = {
|
||||
|
||||
@ -382,6 +382,7 @@
|
||||
#include "sql/engine/expr/ob_expr_st_contains.h"
|
||||
#include "sql/engine/expr/ob_expr_st_within.h"
|
||||
#include "sql/engine/expr/ob_expr_priv_st_asewkb.h"
|
||||
#include "sql/engine/expr/ob_expr_current_scn.h"
|
||||
#include "sql/engine/expr/ob_expr_name_const.h"
|
||||
#include "sql/engine/expr/ob_expr_format_bytes.h"
|
||||
#include "sql/engine/expr/ob_expr_format_pico_time.h"
|
||||
@ -984,6 +985,7 @@ void ObExprOperatorFactory::register_expr_operators()
|
||||
REG_OP(ObExprDesDecrypt);
|
||||
REG_OP(ObExprDesEncrypt);
|
||||
REG_OP(ObExprEncrypt);
|
||||
REG_OP(ObExprCurrentScn);
|
||||
REG_OP(ObExprEncode);
|
||||
REG_OP(ObExprDecode);
|
||||
REG_OP(ObExprICUVersion);
|
||||
@ -1282,6 +1284,7 @@ void ObExprOperatorFactory::register_expr_operators()
|
||||
REG_OP_ORCL(ObExprJsonExists);
|
||||
REG_OP_ORCL(ObExprJsonArray);
|
||||
REG_OP_ORCL(ObExprJsonObject);
|
||||
REG_OP_ORCL(ObExprCurrentScn);
|
||||
REG_OP_ORCL(ObExprTreat);
|
||||
REG_OP_ORCL(ObExprGeneratorFunc);
|
||||
REG_OP_ORCL(ObExprZipf);
|
||||
|
||||
Reference in New Issue
Block a user