fix rownum to limit bug

This commit is contained in:
obdev
2023-03-21 16:26:06 +00:00
committed by ob-robot
parent 99764bc507
commit 600227d1cb
5 changed files with 146 additions and 102 deletions

View File

@ -4102,22 +4102,35 @@ int ObOptimizerUtil::convert_rownum_filter_as_offset(ObRawExprFactory &expr_fact
ObSQLSessionInfo *session_info,
const ObItemType filter_type,
ObRawExpr *const_expr,
ObRawExpr *&offset_int_expr)
ObRawExpr *&offset_int_expr,
ObRawExpr *zero_expr,
bool &offset_is_not_neg,
ObTransformerCtx *ctx)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(const_expr) || OB_ISNULL(session_info)
if (OB_ISNULL(const_expr) || OB_ISNULL(session_info) || OB_ISNULL(ctx) || OB_ISNULL(zero_expr)
|| OB_UNLIKELY(filter_type != T_OP_GE && filter_type != T_OP_GT)
|| OB_UNLIKELY(!const_expr->get_result_type().is_integer_type()
&& !const_expr->get_result_type().is_number())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected null", K(ret), K(const_expr), K(session_info), K(filter_type));
} else if (T_OP_GT == filter_type) {
if (OB_FAIL(floor_number_as_limit_offset_value(expr_factory, session_info,
if (OB_FAIL(ObTransformUtils::compare_const_expr_result(ctx, const_expr, T_OP_GE,
0, offset_is_not_neg))) {
LOG_WARN("offset value is negative calc failed", K(ret));
} else if (!offset_is_not_neg) {
offset_int_expr = zero_expr;
} else if (OB_FAIL(floor_number_as_limit_offset_value(expr_factory, session_info,
const_expr, offset_int_expr))) {
LOG_WARN("failed to floor number as offset value", K(ret));
}
} else if (T_OP_GE == filter_type) {
if (OB_FAIL(ceil_number_as_limit_offset_value(expr_factory, session_info,
if (OB_FAIL(ObTransformUtils::compare_const_expr_result(ctx, const_expr, T_OP_GE,
0, offset_is_not_neg))) {
LOG_WARN("offset value is negative calc failed", K(ret));
} else if (!offset_is_not_neg) {
offset_int_expr = zero_expr;
} else if (OB_FAIL(ceil_number_as_limit_offset_value(expr_factory, session_info,
const_expr, offset_int_expr))) {
LOG_WARN("failed to ceil number as offset value", K(ret));
}