Support uuid_short in mysql mode.

This commit is contained in:
al0
2021-11-30 11:13:10 +08:00
committed by LINxiansheng
parent d06570baf4
commit e28151b107
9 changed files with 143 additions and 4 deletions

View File

@ -189,6 +189,7 @@
#include "ob_expr_any_value.h"
#include "ob_expr_validate_password_strength.h"
#include "ob_expr_benchmark.h"
#include "ob_expr_uuid_short.h"
namespace oceanbase {
using namespace common;
@ -710,7 +711,7 @@ static ObExpr::EvalFunc g_expr_eval_functions[] = {
NULL, /* 445 */
NULL, /* 446 */
NULL, /* 447 */
NULL, /* 448 */
ObExprUuidShort::eval_uuid_short, /* 448 */
ObExprBenchmark::eval_benchmark, /* 449 */
ObExprExportSet::eval_export_set, /* 450 */
ObExprInet6Aton::calc_inet6_aton, /* 451 */

View File

@ -273,6 +273,7 @@
#include "sql/engine/expr/ob_expr_any_value.h"
#include "sql/engine/expr/ob_expr_validate_password_strength.h"
#include "sql/engine/expr/ob_expr_benchmark.h"
#include "sql/engine/expr/ob_expr_uuid_short.h"
using namespace oceanbase::common;
namespace oceanbase {
@ -614,6 +615,7 @@ void ObExprOperatorFactory::register_expr_operators()
REG_OP(ObExprDllUdf);
REG_OP(ObExprExp);
REG_OP(ObExprAnyValue);
REG_OP(ObExprUuidShort);
/* subquery comparison experator */
REG_OP(ObExprSubQueryRef);
REG_OP(ObExprSubQueryEqual);

View File

@ -0,0 +1,78 @@
/*
* Copyright 2014-2021 Alibaba Inc. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* ob_expr_uuid_short.cpp is for uuid_short function
*
* Date: 2021/8/20
*
* Authors:
* ailing.lcq<ailing.lcq@alibaba-inc.com>
*
*/
#define USING_LOG_PREFIX SQL_RESV
#include "sql/engine/expr/ob_expr_uuid_short.h"
#include "observer/ob_server_struct.h"
#include "lib/time/ob_time_utility.h"
using namespace oceanbase::common;
namespace oceanbase {
namespace sql {
ObExprUuidShort::ObExprUuidShort(ObIAllocator &alloc)
: ObFuncExprOperator(alloc, T_FUN_SYS_UUID_SHORT, N_UUID_SHORT, 0, NOT_ROW_DIMENSION)
{}
ObExprUuidShort::~ObExprUuidShort()
{}
/**
* Note:
* The total number of serverids over(>=) 256 will not guarantee uniqueness,
* but we will not report an error, because this is a undefined behavior in mysql.
* In short, users should need to know this.
*/
uint64_t ObExprUuidShort::generate_uuid_short()
{
// uuid_short
// | <8> | <32> | <24>
// server_id server_start_time incremented_variable
static volatile uint64_t server_id_and_server_startup_time = ((GCTX.server_id_ & 255) << 56) |
((static_cast<uint64_t>(common::ObTimeUtility::current_time() / 1000000) << 24) &
((static_cast<uint64_t>(1) << 56) - 1));
uint64_t uuid_short = ATOMIC_AAF(&server_id_and_server_startup_time, 1);
LOG_DEBUG("uuid_short generated.", K(uuid_short));
return uuid_short;
}
int ObExprUuidShort::calc_result0(common::ObObj &result, common::ObExprCtx &expr_ctx) const
{
int ret = OB_SUCCESS;
UNUSED(expr_ctx);
result.set_uint64(generate_uuid_short());
return ret;
}
int ObExprUuidShort::cg_expr(ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr, ObExpr &rt_expr) const
{
UNUSED(raw_expr);
UNUSED(expr_cg_ctx);
rt_expr.eval_func_ = ObExprUuidShort::eval_uuid_short;
return OB_SUCCESS;
}
int ObExprUuidShort::eval_uuid_short(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum)
{
int ret = OB_SUCCESS;
UNUSED(expr);
UNUSED(ctx);
expr_datum.set_uint(generate_uuid_short());
return ret;
}
} // namespace sql
} // namespace oceanbase

View File

@ -0,0 +1,51 @@
/*
* Copyright 2014-2021 Alibaba Inc. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* ob_expr_uuid_short.h is for uuid_short function
*
* Date: 2021/8/20
*
* Authors:
* ailing.lcq<ailing.lcq@alibaba-inc.com>
*
*/
#ifndef _OB_EXPR_UUID_SHORT_H_
#define _OB_EXPR_UUID_SHORT_H_
#include "sql/engine/expr/ob_expr_operator.h"
namespace oceanbase {
namespace sql {
class ObExprUuidShort : public ObFuncExprOperator {
public:
explicit ObExprUuidShort(common::ObIAllocator &alloc);
virtual ~ObExprUuidShort();
virtual int calc_result_type0(ObExprResType &type, common::ObExprTypeCtx &type_ctx) const;
virtual int calc_result0(common::ObObj &result, common::ObExprCtx &expr_ctx) const;
virtual int cg_expr(ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr, ObExpr &rt_expr) const override;
static int eval_uuid_short(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum);
private:
static uint64_t generate_uuid_short();
DISALLOW_COPY_AND_ASSIGN(ObExprUuidShort) const;
};
inline int ObExprUuidShort::calc_result_type0(ObExprResType &type, common::ObExprTypeCtx &type_ctx) const
{
UNUSED(type_ctx);
type.set_uint64();
return common::OB_SUCCESS;
}
} // namespace sql
} // namespace oceanbase
#endif /* _OB_EXPR_UUID_SHORT_H_ */
// select uuid_short();